Hi Guys,
I'm running a query on a 'contact info' table that is basically a list of addresses for an account. The primary key for this table is 'address_id'
A previous query has already determined which of the 'address_id' records is they 'primary' address.
I want to query for all of the addresses for a specific member, but have the 'primary' address be the first in the list.
I was thinking about doing a union on two selects.. first select grabbing only record that matches the primary id, and the 2nd grabbing all the records that don't match.. then I'd have the first record being the primary, and then all the rest following..
Ideas?
I'm running a query on a 'contact info' table that is basically a list of addresses for an account. The primary key for this table is 'address_id'
A previous query has already determined which of the 'address_id' records is they 'primary' address.
I want to query for all of the addresses for a specific member, but have the 'primary' address be the first in the list.
I was thinking about doing a union on two selects.. first select grabbing only record that matches the primary id, and the 2nd grabbing all the records that don't match.. then I'd have the first record being the primary, and then all the rest following..
Ideas?
Code:
SELECT *
FROM tbl_member_contacts
WHERE member_id = #member_id#
and contact_id = #primary_contact_id#
UNION
SELECT *
FROM tbl_member_contacts
WHERE member_id = "#member_id#"
and contact_id <> "#primary_contact_id#"
