I am seeking a way in mySQL to select only records that have corresponding records in a linked table. I am likely suffering tunnel vision, or otherwise missing something simple.
I have the following query which currently works besides this requirement above:
SELECT P.ID, P.NAME, P.SEO_NAME, CI.City, R.Region, C.Country
FROM PROPERTIES P
LEFT JOIN Cities CI ON P.CITY_ID = CI.CityId
LEFT JOIN Regions R ON P.REGION_ID = R.RegionID
LEFT JOIN Countries C ON P.COUNTRY_ID = C.CountryId
WHERE APPROVED = '1' AND REGION_ID = '5400'
ORDER BY RAND() LIMIT 1;
This is related to a previous question of mine, here: Select rows Having Count in linked table
While the answer in this linked thread worked for me at the time, I now require the additional information in the query above. Is there any way I can limit it so that only records with records in the linked table PROPERTY_PHOTOS PP
(which links ON P.ID = PP.PROPERTY_ID
)
Thanks in advance for any input.