N
N
NibiruanChild2017-01-14 16:31:42
MySQL
NibiruanChild, 2017-01-14 16:31:42

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 ;

But points belong to the user (users table), and in the current form, points is checked for the object (objects table)
SQL query gurus, please help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NibiruanChild, 2017-01-14
@NibiruanChild

replaced
by

AND userID IN ( SELECT userID 
                FROM users 
                WHERE points > 0)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question