SQL query not working for respective output

  Kiến thức lập trình

below is my query, i have also attached the expected out out and current query result output.. how can I update the query to get the expected result?

select
    bookings.id as departure,
    return_detail .id as return_id
from
    bookings
left join bookings return_detail on
    bookings.trip_id = return_detail .trip_id
left join booking_passengers bp on
    bookings.id = bp.bp_booking_id
left join booking_passengers return_bp on
    return_detail .id = return_bp .bp_booking_id
where
    bp.bp_passenger_id = 31
    and return_bp .bp_passenger_id = 31
    --and bp.id != return_bp .id
order by
    bookings.id asc

enter image description here

Expected Output:

41-42
43-44
null-58
83-84
91-null

LEAVE A COMMENT