Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i wonder if there is a query (PHP + MySQL code), for having the following rows in my table:

    id name    featured
    ----------------
    1 Robert   0
    2 John     1
    3 Pax      1
    4 Max      0
    5 Emily    0
    6 Sara     0
    7 Estella  0

Shows the following in my page (with priority of featured column value and order by ASC to accommodate the remaining):

    id name    featured
    ----------------
    2 John     1
    3 Pax      1
    1 Robert   0
    4 Max      0
    5 Emily    0
    6 Sara     0
    7 Estella  0

This is my actual code:

$sql = "SELECT * FROM employees ORDER BY id desc';

I hope someone help me, I do not find something similar in Google :/

share|improve this question

3 Answers

$sql = "SELECT * FROM employees ORDER BY featured desc';
share|improve this answer

You need to first order by featured column and then order by id

SELECT * FROM employees ORDER BY featured DESC, id ASC

See this SQLFiddle

share|improve this answer
@Downvotes, What's the problem in this answer? – hims056 Dec 6 '12 at 4:38

try this

 SELECT * FROM employees ORDER BY featured desc, id asc
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.