SELECT SINVEN.id as shared_inventory_plan_Id,flights.id, flights.departure_city_id , flights.departure_airport_id , 
airport.id AS airport_id, airport.name AS airport_name, airport.airport_code AS airport_code,departure_city.name AS departure_city_name, departure_city.city_code AS departure_city_code,SINVEN.share_plan as vendor_share_plan
 FROM flights AS flights 
 INNER JOIN airports AS airport ON  flights.departure_airport_id = airport.id 
INNER JOIN cities AS departure_city ON  flights.departure_city_id = departure_city.id 
INNER join share_inventories as SINVEN on SINVEN.share_by_user_id = flights.user_id 
 INNER join planwise_seat_availabilities as PWSA on PWSA.flight_id = flights.id
 WHERE flights.status = 1 
 and PWSA.plan_no=SINVEN.share_plan 
 and  SINVEN.share_to_user_id IN (select GROUP_CONCAT(id) from users where role_id=1)
and  ADDTIME(DATE_SUB(PWSA.flight_date,INTERVAL flights.close_before_days DAY),flights.close_before_time) >=  now() 
 and  PWSA.available_seats > 0 
 AND flights.return_flight = 0
 and SINVEN.status = 1 
 and SINVEN.accepted_status=1
 and flights.user_id IN (2,3) 
 GROUP BY departure_city_id, departure_airport_id ORDER BY flights.id DESC 