Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6128625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:38:52+00:00 2026-05-23T16:38:52+00:00

I have what I suspect is an easy problem, but my sql skills just

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:38:53+00:00Added an answer on May 23, 2026 at 4:38 pm
        SELECT P.ID,COUNT(*)
          FROM PROPERTIES P
             , PROPERTY_PHOTOS PP
         WHERE PP.PROPERTY_ID = P.ID 
       GROUP BY P.ID
        HAVING COUNT(*) > 0
    

    Or actually, a regular join should work if you don’t care about the count

    SELECT DISTINCT P.ID
      FROM PROPERTIES P
         , PROPERTY_PHOTOS PP
     WHERE PP.PROPERTY_ID = P.ID 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I suspect there is an easy answer for this question but I can't find
I have the following situation in code, which I suspect may be a bit
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
I suspect the solution to my problem to be very easy with LINQ to
I have some fundamental points/questions about OpenGL, not all involving code but concepts as
One day I suspect I'll have to learn hadoop and transfer all this data
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Now this is probably really easy but being the tool that I am, I'm
it seems to me that this is kind of a very easy question, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.