Answer the question
In order to leave comments, you need to log in
How to add a condition from another MySQL table?
There is a users table with users
userID ... points
There is a table objects with objects belonging to users
userID ... object
Input data - the user ID under which we are logged in.
I need to select 1 random object of any other user who has game points (points > 0) with ONE request.
i.e. I need the following
SELECT *
FROM objects
WHERE userID <> 99999
AND points > 0
ORDER BY RAND()
LIMIT 1 ;
Answer the question
In order to leave comments, you need to log in
replaced
by
AND userID IN ( SELECT userID
FROM users
WHERE points > 0)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question