hello guys does anyone know how to filter data or sort using like operator the data in JSON_ARRAYAGG() , I want to add Like operator in Following query. how I can achieve this as I am newbie in MySQL
SELECT s.state_id,s.state,
JSON_ARRAYAGG(JSON_OBJECT('city',c.city, 'city_id',c.city_id) /* i want to add like Operator here*/)
AS 'cities'
FROM `cities` AS c JOIN states AS s
WHERE s.state_id = c.state_id GROUP BY State.
i want to sort cities using like operator
These are the create table schema for citi & state table:
create table `cities` (
`city_id` int (11),
`city` varchar (270),
`state_id` int (11),
`is_active` tinyint (1),
`created_at` datetime ,
`updated_at` datetime
);
insert into `cities` (`city_id`, `city`, `state_id`, `is_active`, `created_at`, `updated_at`) values('1','Port Blair*','1','1','2021-03-31 07:25:28','2021-03-31 07:25:28');
insert into `cities` (`city_id`, `city`, `state_id`, `is_active`, `created_at`, `updated_at`) values('2','Adoni','2','1','2021-03-31 07:25:28','2021-03-31 07:25:28');
insert into `cities` (`city_id`, `city`, `state_id`, `is_active`, `created_at`, `updated_at`) values('3','Amalapuram','2','1','2021-03-31 07:25:28','2021-03-31 07:25:28');
insert into `cities` (`city_id`, `city`, `state_id`, `is_active`, `created_at`, `updated_at`) values('4','Anakapalle','2','1','2021-03-31 07:25:28','2021-03-31 07:25:28');
insert into `cities` (`city_id`, `city`, `state_id`, `is_active`, `created_at`, `updated_at`) values('5','Anantapur','2','1','2021-03-31 07:25:28','2021-03-31 07:25:28');
insert into `cities` (`city_id`, `city`, `state_id`, `is_active`, `created_at`, `updated_at`) values('6','Bapatla','2','1','2021-03-31 07:25:28','2021-03-31 07:25:28');
insert into `cities` (`city_id`, `city`, `state_id`, `is_active`, `created_at`, `updated_at`) values('7','Bheemunipatnam','2','1','2021-03-31 07:25:28','2021-03-31 07:25:28');
state table:
create table `states` (
`state_id` int (11),
`state` varchar (180),
`is_active` tinyint (1),
`created_at` datetime ,
`updated_at` datetime
);
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('1','Andaman and Nicobar Islands','1','2021-03-31 06:30:04','2021-03-31 06:30:04');
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('2','Andhra Pradesh','1','2021-03-31 06:30:04','2021-03-31 06:30:04');
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('3','Arunachal Pradesh','1','2021-03-31 06:30:04','2021-03-31 06:30:04');
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('4','Assam','1','2021-03-31 06:30:04','2021-03-31 06:30:04');
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('5','Bihar','1','2021-03-31 06:30:04','2021-03-31 06:30:04');
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('6','Chandigarh','1','2021-03-31 06:30:04','2021-03-31 06:30:04');
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('7','Chhattisgarh','1','2021-03-31 06:30:04','2021-03-31 06:30:04');
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('8','Dadra and Nagar Haveli','1','2021-03-31 06:30:04','2021-03-31 06:30:04');
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('9','Delhi','1','2021-03-31 06:30:04','2021-03-31 06:30:04');
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('10','Goa','1','2021-03-31 06:30:04','2021-03-31 06:30:04');
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('11','Gujarat','1','2021-03-31 06:30:04','2021-03-31 06:30:04');
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('12','Haryana','1','2021-03-31 06:30:04','2021-03-31 06:30:04');
insert into `states` (`state_id`, `state`, `is_active`, `created_at`, `updated_at`) values('13','Himachal Pradesh','1','2021-03-31 06:30:04','2021-03-31 06:30:04');