Table subject:
+--------+----+
| name | id |
+--------|----+
| apple | 3 |
| banana | 1 |
| tree | 4 |
| horse | 6 |
| bird | 7 |
| raq | 2 |
+--------+----+
So I try to have an ouput like that (if, for example, my $id_subject = 4, my next row MUST be 5 -6 7-1….)
+--------+----+
| name | id |
+--------+----+
| tree | 4 |
| horse | 6 |
| bird | 7 |
| banana | 1 |
| raq | 2 |
| apple | 3 |
+--------+----+
My query:
select subject_url,subjects.id
from students_group
left join teacher_group on teacher_group.group_school_id = students_group.group_id
left join subjects on teacher_group.subject_id = subjects.id
where students_group.user_id = 83
ORDER BY subjects.id = 5 desc
But I got this output:
+--------+----+
| name | id |
+--------+----+
| tree | 4 |
| apple | 3 |
| banana | 1 |
| horse | 6 |
| bird | 7 |
| raq | 2 |
+--------+----+
How can I make it work as expected?
1 Answer