0

i have a single mysql table with at minimum userId, wager. Data can be

userId = 1 wager = 10.00, userId = 2 wager = 5.00, userId = 3 wager = 1.00.

I want to run a select with a userId param that returns all userId's that are <= the wager for that user So if userId = 2 I get back all other users with a wager of 5.00 or less. Query does a lot more than this with one join but just need some help or best approach with the above

2 Answers 2

6

You can do it with a self-join:

SELECT u1.*
FROM user AS u1
INNER JOIN user AS u2 ON u1.wager <= u2.wager
WHERE u2.userId = ?
Sign up to request clarification or add additional context in comments.

Comments

0
SELECT userA.*
FROM user AS userA,user AS userB 
WHERE userA.wager <= userB.wager 
AND userA.userId=userB.userId
AND userB.userId = 2

It's a good question and hope it helps you. I think most people forgot to link the userId together and it may need to link the userId together.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.