MySQL - query to show guests with same last_name + booking_date [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












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?










share|improve this question















closed as off-topic by Christopher, ctrl-alt-delor, mosvy, RalfFriedl, thrig Nov 20 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 at 14:18










  • @ctrl-alt-delor perhaps, join g1 to b1 and g2 to b2?
    – qoph
    Nov 20 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 at 14:33










  • thanks, wrong exchange
    – qoph
    Nov 20 at 14:36














up vote
1
down vote

favorite












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?










share|improve this question















closed as off-topic by Christopher, ctrl-alt-delor, mosvy, RalfFriedl, thrig Nov 20 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 at 14:18










  • @ctrl-alt-delor perhaps, join g1 to b1 and g2 to b2?
    – qoph
    Nov 20 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 at 14:33










  • thanks, wrong exchange
    – qoph
    Nov 20 at 14:36












up vote
1
down vote

favorite









up vote
1
down vote

favorite











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?










share|improve this question















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?







mysql sql mariadb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 14:29









ctrl-alt-delor

10.2k41955




10.2k41955










asked Nov 20 at 13:48









qoph

135




135




closed as off-topic by Christopher, ctrl-alt-delor, mosvy, RalfFriedl, thrig Nov 20 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.




closed as off-topic by Christopher, ctrl-alt-delor, mosvy, RalfFriedl, thrig Nov 20 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 at 14:18










  • @ctrl-alt-delor perhaps, join g1 to b1 and g2 to b2?
    – qoph
    Nov 20 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 at 14:33










  • thanks, wrong exchange
    – qoph
    Nov 20 at 14:36
















  • it has been a while, and I have not done much sql, but do you need two joins.
    – ctrl-alt-delor
    Nov 20 at 14:18










  • @ctrl-alt-delor perhaps, join g1 to b1 and g2 to b2?
    – qoph
    Nov 20 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 at 14:33










  • thanks, wrong exchange
    – qoph
    Nov 20 at 14:36















it has been a while, and I have not done much sql, but do you need two joins.
– ctrl-alt-delor
Nov 20 at 14:18




it has been a while, and I have not done much sql, but do you need two joins.
– ctrl-alt-delor
Nov 20 at 14:18












@ctrl-alt-delor perhaps, join g1 to b1 and g2 to b2?
– qoph
Nov 20 at 14:26




@ctrl-alt-delor perhaps, join g1 to b1 and g2 to b2?
– qoph
Nov 20 at 14:26




3




3




I'm voting to close this question, because it would be better served on dba.stackexchange.com
– ctrl-alt-delor
Nov 20 at 14:33




I'm voting to close this question, because it would be better served on dba.stackexchange.com
– ctrl-alt-delor
Nov 20 at 14:33












thanks, wrong exchange
– qoph
Nov 20 at 14:36




thanks, wrong exchange
– qoph
Nov 20 at 14:36















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?