I have a database of company registrants (for a search/directory functionality). We’ve added a new table to hold ‘enhanced’ information for registrants that pay for this feature (such as advertisements/additional images/logos etc). Right now the new table just holds the registrants unique identifier, and a few additional fields (paths to images etc). A user can search for users with specific criteria, and the enhanced listings should appear at the top of the list. The results should not show any registrant twice (so if a user has an enhanced listing they should only appear in the top ‘enhanced listing’ area). How can I accomplish this?
I have a database of company registrants (for a search/directory functionality). We’ve added a
Share
Left outer join from the old table to the new table.
Prepend to your query’s ‘order by’ ‘case when new_table.id is null then 1 else 0 end’
So if you had this:
You’d have this:
Edit: I left out the ‘left’ from the outer join in the code.