To simplify the problem down for the question, I have a listings table and a listings_featured table. The main listings tables holds the main data for all listings but the listings_featured table holds data for only listings which are featured.
I want to display listings ordered by whether they are featured or not first, meaning the rows which have a match when doing a LEFT or RIGHT JOIN should come first. How would I go about doing this with just one query rather than two?
EDIT
Also, is it possible to add a WHERE condition to the query that only applies to the joined records? For example, out of the featured listings, I only want the ones which have the condition WHERE featured_end_date > now() – this should only apply to the joined records. This is because the duration for which a listing is featured will be different to the actual expiry date of the listing.
lf.lid IS NULLisFALSEfor all featured listings so while sorting they get put before other listings.EDIT
Added WHERE condition