0

I am trying to run the following sql query:

select *
from fblikes
order by likes desc (select * from fblikes order by id asc limit 0,4)

it gives the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(select * from fblikes order by id asc limit 0,4) LIMIT 0, 30' at line 1

what i want to achieve is that the query should select first 5 entries by 'id' (ascending) and out of those 5 it should order them by 'likes' (descending).

I am poor at nested queries. Any Help?

1
  • 1
    @fthella thanks for the edit. I'll take care to properly edit the question from now on Commented Feb 17, 2013 at 11:14

1 Answer 1

2
select * 
from 
(
   select * 
   from fblikes 
   order by id asc 
   limit 0,4
) AS Sub
order by likes desc ;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that worked! Will accept this as the correct answer once the timeoff ends! Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.