I have two tables and a linking table between them, One of users and one of vacations and a linking table of likes, I try to bring up all the vacations that a certain user did not like And I get the same vacation twice because two other people liked her. Is there a way NSQL will bring me just one of them.
These are the users
id u_name
1 Gabi Ashkenazi
2 Johnny Tribiani
3 Bernie Stinson
4 Goku son
5 Bo Bennett
These are the vacations
id v_name
1 Venice
2 Rome
3 Maldives
4 Tokyo
5 Israel
6 Berlin
7 Prague
8 never Land
And the linking table looks like this
id u_id v_id
5 2 7
3 1 6
4 2 5
9 4 4
Would something like this work for you? Find all the vacations that Johnny likes and then return the list that he doesn't like:
SELECT *
FROM Vacations
WHERE v_name not IN
(
SELECT v_name
FROM Users
JOIN Linking
ON Users.ID = Linking.U_id
JOIN Vacations On Linking.v_id = Vacations.ID
WHERE Users.ID = 2
);