I have two tables. One has some product details, the other holds various photos per product. For my problem only the following fields are used:
tableA id - prodName tableB id - prod_id - photoName where tableA.id = tableB.prod_id
Not all products have photos (in other words not every tableA.id exists in tableB). I am only interested in the first photo of each product (that has photos).
What query would allow me to list all products on my page, showing first the ones that have photos and at the end the ones that don't? Both sets must be alphabetical ordered based on product name.
So far i have tested the following without 100% success
Using two queries: Query 1st: SELECT prod_id FROM tableB WHERE photoName <> '' GROUP BY prod_id ORDER BY photo_name this will give me (with some php scripting) a list (comma seperated) of all products with photos, sorted by photo name Query 2: SELECT ..... FROM tableA WHERE ..... ORDER BY FIND_IN_SET(id, '$myList') DESC, prodName ASC The second query will filter the products that have/have not photos, but not sorted by product name (because the original list is ordered by photo name).
Is there a way to accomplish what i want in a single query (if possible)?