SELECT (select distinct role_id from users where id=SINVEN.share_to_user_id) as share_to_user_role_id, FAS.add_margin,FAS.margin,FAS.client_discount,FAS.vendor_discount,USER.company_name, USER.role_id, FARETAX.base_fare, FARETAX.fee_taxes, SINVEN.credit_limit as inventory_credit_limit, SINVEN.share_price_breakup as inventory_price_breckup, SINVEN.share_plan,SINVEN.share_by_user_id,SINVEN.share_to_user_id,FGT.id as flight_id,FGT.user_id,(select option_value from options where user_id=FGT.user_id and option_key="special_info" limit 0,1) as special_info, FGT.re_flight_number,FGT.flight_number,FGT.name,FGT.airline_id, FGT.departure_city_id,FGT.departure_airport_id,FGT.dep_terminal_no_id, FGT.departure_time,FGT.arrival_city_id,FGT.arrival_airport_id,FGT.arrival_terminal_no_id,FGT.arrival_date,FGT.arrival_time,FGT.return_flight,FGT.checkin_baggages_adult,FGT.checkin_baggages_infant,FGT.cabin_baggages_adult,FGT.cabin_baggages_children,FGT.checkin_baggages_children,FGT.cabin_baggages_children,FGT.cabin_baggages_infant,departure_city.country_id as departure_country_id,departure_city.name as departure_city_name,arrival_city.name as arrival_city_name, arrival_city.country_id as arrival_country_id,departure_airports.name as departure_airport_name,departure_airports.airport_code as departure_airport_code,arrival_airports.name as arrival_airport_name ,arrival_airports.airport_code as arrival_airport_code ,airlines.name as airlines_name,airlines.logo as airlines_logo,airlines.airline_no,airlines.airline_code,FPNR.date as ticket_date ,FPNR.return_dep_date as return_dep_date,FPNR.pnr_number as pnr_number,FPNR.infant_price as infant_price,FPNR.block_seat as block_seat,PSA.available_seats as total_available_seats FROM flights as FGT
                            INNER join planwise_seat_availabilities as PSA on PSA.flight_id = FGT.id 
                            INNER join flight_pnrs as FPNR on FPNR.flight_id = FGT.id 
                            INNER join flight_fare_taxes as FARETAX on FARETAX.flight_id = FGT.id 
                            INNER join users as USER on USER.id = FGT.user_id 
                            INNER join flght_api_settings as FAS on FAS.user_id = 1 
                            INNER join share_inventories as SINVEN on SINVEN.share_by_user_id = FGT.user_id 
                            INNER join cities as  departure_city on departure_city.id = FGT.departure_city_id
                            INNER join cities as  arrival_city on arrival_city.id = FGT.arrival_city_id 
                            INNER join airports as  departure_airports on departure_airports.id = FGT.departure_airport_id 
                            INNER join airports as  arrival_airports on arrival_airports.id = FGT.arrival_airport_id 
                            INNER join airlines as  airlines on airlines.id = FGT.airline_id 
                            WHERE FGT.status = 1 
                            and now() <=  ADDTIME(DATE_SUB('2021-07-21',INTERVAL FGT.close_before_days DAY),FGT.close_before_time) 
                            and return_flight=0 
                            and departure_city_id = 543
                            and departure_airport_id=1023
                            and  arrival_city_id=1010
                            and arrival_airport_id=2110
                            and FGT.user_id IN (2,3) 
                            and SINVEN.id IN  (9,10)  
                            and PSA.plan_no = share_plan
							and PSA.flight_date = '2021-07-21' 
                            and PSA.available_seats > 0
                            and FPNR.available_seat > 0 
                            and FPNR.date ='2021-07-21' 
                            and SINVEN.status = 1
                            and SINVEN.accepted_status=1 
                            and FARETAX.date ='2021-07-21' 
                            group by FPNR.flight_id ORDER by USER.role_id desc