1

I have a guest table and a booking table and I am attempting to query how to find guests who share the same last names with the same booking date.

The result should output their last_name and first_names without any duplicate results.

SELECT g1.first_name, 
       g2.first_name,
       g1.last_name, 
       b.booking_date
FROM guest g1, guest g2 JOIN booking b ON id=booking_id
WHERE g1.last_name = g2.last_name AND g1.id<>g2.id AND b.booking_date=b.booking_date;

When I run this, I get back the empty set.

Where am I going wrong?

closed as off-topic by Christopher, ctrl-alt-delor, mosvy, RalfFriedl, thrig Nov 20 '18 at 18:48

  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • it has been a while, and I have not done much sql, but do you need two joins. – ctrl-alt-delor Nov 20 '18 at 14:18
  • @ctrl-alt-delor perhaps, join g1 to b1 and g2 to b2? – qoph Nov 20 '18 at 14:26
  • 3
    I'm voting to close this question, because it would be better served on dba.stackexchange.com – ctrl-alt-delor Nov 20 '18 at 14:33

Browse other questions tagged or ask your own question.