I hope my title makes sense but basically what I need to do is select some rows from a mysql table but I want one particular row to always be listed first. Normally I would use "order by field" for this but this particular row has to match a value in another table.
SCHEDULES TABLE
----------
ID
NAME
COMPANYID
DESCRIPTION
COMPANIES TABLE
----------
ID
NAME
ACTIVESCHEDULEID
So I want to select all the schedules from schedules table where companyid = 1, but the schedule that is the active schedule for this company needs to be listed first, and that bit of information is stored in the companies table.
I was hoping I could do something like this:
select s.id
from schedules s, companies c
where s.companyid = c.id
and s.companyid = 1
order by field(s.id,s.id = c.activescheduleid)
But that's not working for me. Any ideas?