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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:38:50+00:00 2026-06-08T19:38:50+00:00

I’m trying to get multiple attributes (e.g bedrooms, bathrooms, etc) from a few tables

  • 0

I’m trying to get multiple attributes (e.g bedrooms, bathrooms, etc) from a few tables yes I can only seem to get one attribute with my current query. What am I missing?

What I am ultimately trying to find is property_id’s with 2 bathrooms and 2 bedrooms. In this case, my desired results are property id’s 1 and 4.

Here’s my example on sqlfiddle

Example tables:

property
--------
id 
1
2
3
4

attribute
---------
id name
1  bedrooms
2  bathrooms

attribute_value
---------------------
id attribute_id value
1  1            1
2  1            2
3  1            3
4  2            1
5  2            2
6  2            3

property_attributes
------------------------------
property_id attribute_value_id
1           2
1           5
2           2
2           4
3           1
3           4
4           2
4           5 

This query can produce the results I want if I only want to see a query based on single attribute:

SELECT p.property_id
FROM property p
INNER JOIN property_attribute pa ON p.property_id = pa.property_id
INNER JOIN property_area pc ON p.property_id = pc.property_id
WHERE pa.attribute_value_id
IN (
SELECT av.attribute_value_id
FROM attribute_value av
INNER JOIN attribute a ON av.attribute_id = a.attribute_id
WHERE a.name like 'bedrooms' AND av.value like '2')

But what must I do to get results with more attributes (e.g. WHERE a.name like ‘bathrooms’ AND av.value like ‘2’)? If I add another subquery in the main where clause, it doesn’t return any results.

/// EDIT ///

here is the solution that worked for me if anyone else winds up in such a situation:

SELECT p.property_id
FROM property p
INNER JOIN property_attribute pa ON p.property_id = pa.property_id
INNER JOIN property_attribute pa2 ON p.property_id = pa2.property_id
INNER JOIN property_attribute pa3 ON p.property_id = pa3.property_id
WHERE pa.attribute_value_id = 2 
AND pa2.attribute_value_id = 5
AND pa3.attribute_value_id = 7

This makes usage of a self-join.

  • 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-06-08T19:38:52+00:00Added an answer on June 8, 2026 at 7:38 pm

    You have an awful lot of indirection in your schema. Is there any particular point why you need the property_attribute table? Do you expect a single attribute value to be shared by many properties?

    In any case, here is the query for you. Very much in the spirit of the two possible duplicates I mentioned above.

    SELECT property.property_id,
           bedrooms.value AS bedrooms,
           bathrooms.value AS bathrooms
    FROM property,
         attribute AS bedrooms_attr,
         attribute_value AS bedrooms,
         property_attribute AS bedrooms_prop,
         attribute AS bathrooms_attr,
         attribute_value AS bathrooms,
         property_attribute AS bathrooms_prop
    WHERE bedrooms_attr.name = 'bedrooms'
      AND bedrooms.attribute_id = bedrooms_attr.attribute_id
      AND bedrooms.attribute_value_id = bedrooms_prop.attribute_value_id
      AND bedrooms_prop.property_id = property.property_id
      AND bedrooms.value = 2
      AND bathrooms_attr.name = 'bathrooms'
      AND bathrooms.attribute_id = bathrooms_attr.attribute_id
      AND bathrooms.attribute_value_id = bathrooms_prop.attribute_value_id
      AND bathrooms_prop.property_id = property.property_id
      AND bathrooms.value = 2
    

    Thanks for providing a fiddle with data to play with.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported

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.