I have what I suspect is an easy problem, but my sql skills just aren't there, and Google is not helping me (yet).
I have the following tables (stripped down for ease of reading):
CREATE TABLE IF NOT EXISTS `PROPERTIES` (
`ID` int(11) NOT NULL auto_increment,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=111 ;
CREATE TABLE IF NOT EXISTS `PROPERTY_PHOTOS` (
`ID` int(11) NOT NULL auto_increment,
`PROPERTY_ID` int(11) NOT NULL,
`PHOTO` varchar(128) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=911 ;
Which link on PROPERTIES.ID = PROPERTY_PHOTOS.PROPERTY_ID
What I would like to do is something like:
SELECT P.ID FROM PROPERTIES P WHERE COUNT(SELECT PP.ID FROM PROPERTY_PHOTOS PP WHERE PP.PROPERTY_ID = P.ID) > 0
or
SELECT P.ID FROM PROPERTIES P HAVING COUNT(SELECT PP.ID FROM PROPERTY_PHOTOS PP WHERE PP.PROPERTY_ID = P.ID) > 0
However, both queries are syntactically incorrect.
Can anyone advise on how I would select only records from PROPERTIES that have corresponding records in the PROPERTY_PHOTOS table?