Skylineman Skylineman - 7 months ago 44
PHP Question

MySQL ORDER BY priority with groups?

I'm writing you today because I'd like to know how to manage the following!

An example table:

NAME, PRIORITY, SORT
TEST1, 0, 11:10
TEST2, 1, 11:15
TEST3, 0, 11:20
TEST4, 1, 11:30


I would like to make the following priority listing with ordering to
priority
:

TEST2 (first submitted with priority)
TEST1
TEST3
TEST4

How to do that? I've tried with GROUP BY and so, but not succeed!

Thanks in advance,
Marcell

Answer

Please try this.

  SELECT NAME 
    FROM table
   WHERE PRIORITY = 1
ORDER BY TIME ASC
   LIMIT 1
UNION 
  SELECT NAME 
    FROM table
ORDER BY TIME ASC

that should gave

TEST2 (first submitted with priority) TEST1 TEST3 TEST4

edit forgot priority