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 6390139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:29:23+00:00 2026-05-25T03:29:23+00:00

I am seeking a way in mySQL to select only records that have corresponding

  • 0

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.

  • 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-25T03:29:24+00:00Added an answer on May 25, 2026 at 3:29 am

    One more JOIN, but not LEFT

    SELECT ...
    FROM PROPERTIES P
    ...
    INNER JOIN PROPERTY_PHOTOS PP ON P.ID = PP.PROPERTY_ID
    

    or just

    SELECT ...
    FROM PROPERTIES P
    ...
    JOIN PROPERTY_PHOTOS PP ON P.ID = PP.PROPERTY_ID
    

    because they are the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic users table I want to create in MySQL. I do
I have a MySQL table properly set to the UTF-8 character set. I suspect
I'm seeking the most efficient way to make strings like that abcdefghijklmnop(longer then 15)
I'm using hadoop to update some records in a mysql db... The issue that
I have the MySQL table ID , username , points . I am trying
Does SQLite support seeding the RANDOM() function the same way MySQL does with RAND()
I'm not seeing a way to create, via the HtmlHelper , a SelectListItem that
I have a script that is intended to check whether some value (e.g. option
Let's say we have a table with columns DAY and NUMERO. There can be
First, let me begin by saying that I have done a lot of research

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.