MySQL - query to show guests with same last_name + booking_date [closed]
Clash 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?
mysql sql mariadb
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.
add a comment |
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?
mysql sql mariadb
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.
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
add a comment |
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?
mysql sql mariadb
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
mysql sql mariadb
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.
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.
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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