Reputation: 17
I have this query but I just want to return the top 10 based on the num_guess. I don't know the format of the query. I don't know where to put LIMIT or TOP. Please help!
"SELECT user,num_guess FROM game JOIN difficulty USING (difficulty_no) WHERE difficulty_no=2 ORDER BY num_guess ASC "
Upvotes: 1
Views: 84
Reputation: 415
Yes the limit would work here.
SELECT user,num_guess FROM game
JOIN difficulty USING (difficulty_no)
WHERE difficulty_no=2 ORDER BY num_guess ASC LIMIT 10;
To view more just increase the limit.
Upvotes: 0
Reputation: 1042
use LIMIT 10
"SELECT user,num_guess FROM game
JOIN difficulty USING (difficulty_no)
WHERE difficulty_no=2 ORDER BY num_guess ASC LIMIT 10"
for more information check this http://dev.mysql.com/doc/refman/5.5/en//limit-optimization.html
Upvotes: 0
Reputation: 1815
With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):
-- SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15
SELECT user,num_guess FROM game
JOIN difficulty USING (difficulty_no)
WHERE difficulty_no=2 ORDER BY num_guess ASC limit 0, 10
you can go with LIMIT 10
here in this context
Upvotes: 1
Reputation: 428
use limit 10
something like this
"SELECT user,num_guess FROM game
JOIN difficulty USING (difficulty_no)
WHERE difficulty_no=2 ORDER BY num_guess ASC limit 10"
Upvotes: 3