Answer the question
In order to leave comments, you need to log in
MySQL query from two tables
There are two tables:
games (id, name, image) table with games
uploaded_games (id, user_id, game_id) table with games uploaded by user with user_id
You need to select from the games table only those games that are not in the uploaded_games table .
I did this:
SELECT * FROM games
LEFT JOIN uploaded_games
ON games.id != uploaded_games.game_id AND uploaded_games.user_id != 1 The
request doesn't work (empty request), please point it in the right direction.
Answer the question
In order to leave comments, you need to log in
I hope you know this picture.
Let's say table A is SELECT * FROM games
, and table B is SELECT * FROM uploaded_games WHERE user_id = ?
.
Those. you need to subtract table B from table A (in terms of set theory). In the picture, this is the left column, second from the top.
SELECT *
FROM games as A
LEFT JOIN uploaded_games as B ON (A.game_id = B.game_id)
WHERE B.game_id is NULL AND B.user_id = ?
SELECT *
FROM games
WHERE game_id NOT IN (
SELECT game_id FROM uploaded_games WHERE user_id = ?
)
SELECT * FROM games
LEFT OUTER JOIN uploaded_games
ON games.id = uploaded_games.game_id where uploaded_games.id is null
SELECT * FROM games WHERE id NOT IN (SELECT game_id FROM uploaded_games WHERE 1)
Not quite a correct question, what does user_id have to do with it if you want to select from the games table only those games that are not in the uploaded_games table?
SELECT * FROM games g
LEFT JOIN uploaded_games ug ON g.id=ug.game_id
WHERE ug.game_id IS NULL
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question