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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:28:41+00:00 2026-06-11T06:28:41+00:00

Currently I have two MySQL tables Properties id name 1 Grove house 2 howard

  • 0

Currently I have two MySQL tables

Properties

id    name 
1     Grove house
2     howard house
3     sunny side

Advanced options

prop_id    name
1          Wifi
1          Enclosed garden
1          Swimming pool
2          Swimming pool

As you can see table two contains specific features about the properties

When I only have max 3 options the query below worked just fine. (maybe a little slow but ok) now things have expanded somewhat and i have a max of 12 options that it is possible to search by and its causing me some major speed issues. The query below is for 8 options and as you can see its very messy. Is there a better way of doing what I’m trying to achieve?

SELECT * FROM properties WHERE id in (
select prop_id from advanced_options where name = 'Within 2 miles of sea or river' and prop_id in ( 
    select prop_id from advanced_options where name = 'WiFi' and prop_id in ( 
        select prop_id from advanced_options where name = 'Walking distance to pub' and prop_id in ( 
            select prop_id from advanced_options where name = 'Swimming pool' and prop_id in ( 
                select prop_id from advanced_options where name = 'Sea or River views' and prop_id in ( 
                    select prop_id from advanced_options where name = 'Pet friendly' and prop_id in ( 
                        select prop_id from advanced_options where name = 'Open fire, wood burning stove or a real flame fire-place' and prop_id in ( 
                            select prop_id from advanced_options where name='Off road parking') 
                        ) 
                    ) 
                ) 
            ) 
        ) 
    ) 
)
  • 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-11T06:28:43+00:00Added an answer on June 11, 2026 at 6:28 am

    Like Mike Brant suggest I would consider altering your datamodel to a limit to set and creating a column for each of these in your properties table. But some times the boss comes: “We also need ‘flatscreen tv'” and then you have to go back to the DB and update the scheme and your data access layer.

    A way to move this logic somehow out if the database it to use bitwise comparison. This allows you to make simple queries, but requires a bit of preprocessing before you make your query.

    Judge for yourself.

    I’ve put everything in a test suite for you here sqlfiddle

    The basic idea is that each property in your table has an id that is the power of 2. Like this:

    INSERT INTO `advanced_options` (id, name)
    VALUES
     (1, 'Wifi'),
     (2, 'Enclosing Garden'),
     (8, 'Swimming Pool'),
     (16, 'Grill');
    

    You can then store a single value in your properties table buy adding up the options:

    Wifi + Swimming Pool = 1 + 8 = 9
    

    If you want to find all properties with wifi and a swimming pool you then do like this:

    SELECT * FROM `properties` WHERE `advanced_options` & 9 = 9
    

    If you just wanted swimming pool this would be it:

    SELECT * FROM `properties` WHERE `advanced_options` & 8 = 8
    

    Go try out the fiddle

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

Sidebar

Related Questions

I have two tables in MySQL 5.1.38. products +----+------------+-------+------------+ | id | name |
Currently, I have two MySQL tables. First table stores relation between the friend and
Currently, I have two MySQL tables. First table stores relation between the friend and
I currently have two tables similar to users and programs that are linked through
I have two MySQL database tables: one containing a list of championships and another
I have three large MySQL tables. They are approaching 2 million records. Two of
I'm working on mysql and have two tables with the same schema: preTrial |id|accusedId|articleid|
I am using the latest MySQL. I have two tables: backlinks and pages .
I have two tables in mySQL, notably accounts and subscriber_data. I want to use
I currently have 5 tables in MySQL database. Some of them share foreign keys

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.