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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:02:55+00:00 2026-05-22T17:02:55+00:00

Tech used: MySQL 5.1 I have a MySQL Query below: SELECT property.propertyId, categoryRelationships.categoryId FROM

  • 0

Tech used: MySQL 5.1

I have a MySQL Query below:

SELECT 
  property.propertyId,
  categoryRelationships.categoryId
FROM
  property
LEFT OUTER JOIN categoryRelationships ON (property.propertyId = categoryRelationships.propertyId)
WHERE
 categoryRelationships.categoryId IN (11,12)

This returns a result such as:

propertyId    categoryId
972           11
1071          11
1622          12
1622          11

However what I want to do is only return the propertyId’s where it has both category 11 and 12 in it (in the case above 1622)

I have tried

SELECT 
  property.propertyId,
  categoryRelationships.categoryId
FROM
  property
LEFT OUTER JOIN categoryRelationships ON (property.propertyId = categoryRelationships.propertyId)
WHERE
  categoryRelationships.categoryId = 11
  AND categoryRelationships.categoryId = 12

and

SELECT 
  property.propertyId,
  categoryRelationships.categoryId
FROM
  property
LEFT OUTER JOIN categoryRelationships ON (property.propertyId = categoryRelationships.propertyId)
WHERE
  categoryRelationships.categoryId IN (11)
  AND categoryRelationships.categoryId IN (12)

However this returns no results, it’s driving me a little crazy how to do this.

A simple example of the two tables would be (I am returning a huge amount more info from the property table):

categoryRelationships

categoryRelationshipsId     categoryId      propertyId
2                           9               2136
3                           2               2136
4                           11              1622
5                           12              1622


property

propertyId                  propertyAddress
1622                        1 Anystreet
2136                        156 Stack Road
  • 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-22T17:02:56+00:00Added an answer on May 22, 2026 at 5:02 pm

    This would seem to me to be the clearest, most-straighforward solution:

    SELECT p.propertyaddress, t1.pid, t1.cid 
      FROM categoryRelationships t1
           LEFT JOIN property p ON p.property_id = t1.property_id
     WHERE EXISTS (
               SELECT 1 
                 FROM categoryRelationships t2 
                WHERE t2.pid = t1.pid 
                  AND t2.cid = 11) 
       AND EXISTS (
               SELECT 1 
                 FROM categoryRelationships t3 
                WHERE t3.pid = t1.pid 
                  AND t3.cid = 12);
    

    Since sometimes MySQL isn’t so adept at handling subqueries you could alternatively do something like this:

    SELECT p.propertyaddress, t1.pid, t1.cid 
      FROM categoryRelationships t1 
           LEFT JOIN property p ON p.property_id = t1.property_id
           JOIN categoryRelationships t2 ON t2.pid = t1.pid 
       AND t2.cid = 11 
           JOIN categoryRelationships t3 ON t2.pid = t3.pid 
       AND t3.cid = 12;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Tech used: PHP 5.3.10 Hi, I have an array (example below) I need to
Tech used: MySQL 5.1 and PHP 5.3 I am just designing a new database
I have an application used by pretty tech-savey people and they want small island
i have very serious problem if any tech expert can help...thank you in advance..
I have a git repository - including different tech. Android and iPhone. The folder
I am not terribly familiar with either tech, so bear with me. I have
If you have used indeed.com before, you may know that for the keywords you
making an Access database (2003) that is mainly used by other programmers and tech
I have used JD decompiler for decompiling a jar file. Affter do that I
Just wondering if it used MD5 or what to encrypt passwords. Preparing a tech

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.