[Solved] get one record based upon catname


Without a MCVE and actual requirements on which image you want from the images table and a better understanding of why you need a left join when your where clause makes it behave like an inner… and why the where clause is so complex… …I’m really unsure what the question is after… Here’s a shot… and a DEMO:http://rextester.com/CRBN50943

Sample data expected results always a plus: I made my own and several assumptions

I interperted the question as: I would like a list of the categories along with a image having the earliest alphabetic value for each category.

SELECT
CI.Image,
CI.FileURL,
C.catname,
C.`status`,
C.sortorder,
C.parentID,
CI.CatID
FROM pm_categories C
INNER JOIN pm_categories_images  CI
  ON CI.CatID = C.catID 
INNER JOIN (SELECT Min(Image) MI, catID FROM pm_categories_images group by CATID) Z
 on CI.Image = Z.MI 
 and CI.CatID = Z.CatId
##WHERE C.catname="Videography"
Order by sortOrder

Giving us

+----+------------+-----------------------------------------------+-------------+--------+-----------+----------+-------+
|    |   Image    |                    FileURL                    |   catname   | status | sortorder | parentID | CatID |
+----+------------+-----------------------------------------------+-------------+--------+-----------+----------+-------+
|  1 | guid1.jpg  | https://drive.google.com/BusinessID/Postings/ | Real Estate |      1 |         1 | NULL     |     1 |
|  2 | guid4.jpg  | https://drive.google.com/BusinessID/Postings/ | commercial  |      1 |         2 | NULL     |     2 |
|  3 | guid6.jpg  | https://drive.google.com/BusinessID/Postings/ | Videography |      1 |         3 | NULL     |     3 |
|  4 | guid10.jpg | https://drive.google.com/BusinessID/Postings/ | Other       |      1 |         4 | NULL     |     4 |
|  5 | guid11.jpg | https://drive.google.com/BusinessID/Postings/ | LackingMCVE |      1 |         5 | NULL     |     5 |
+----+------------+-----------------------------------------------+-------------+--------+-----------+----------+-------+

solved get one record based upon catname