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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:29:20+00:00 2026-06-17T06:29:20+00:00

I have tables like products product_attributes ================== ======================================== | id | name | |

  • 0

I have tables like

products            product_attributes
==================  ========================================
| id | name      |  | id | product_id | attribute | value  |
==================  ========================================
| 1  | product 1 |  | 1  | 1          | min       | 2    |
| 2  | product 2 |  | 2  | 1          | max       | 5    |
| 3  | product 3 |  | 3  | 2          | min       | 10   |
| 3  | product 3 |  | 4  | 2          | max       | 15   |
| .. | ...       |  | 5  | 3          | min       | 1    |
==================  | 6  | 3          | max       | 100  |
                    | .. | ...        | ...       | ...  |
                    ========================================

I want to get all the products that fall within a range
I can successfully get a list of the ids that fall with-in the range using

SELECT p.id 
  FROM `products` p INNER JOIN `product_attributes` AS pa ON p.id = pa.product_id   
  WHERE  pa.`min` <= 5 AND  pa.`max` >= 5 GROUP BY p.id

This gives me a list of the ids that i need.
What i can not get to work is to get a TOTAL count of the ids instead of a list so i can not use the group by and then when i do that it messes up the count.

Is the only way to do this is by using the select above in a subselect and counting the
results?

Thanks

  • 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-17T06:29:22+00:00Added an answer on June 17, 2026 at 6:29 am

    Given the structure above, where min and max are on different rows, I would use this:

    select count(id) from (
      select p.id
      from
        `products` p INNER JOIN `product_attributes` AS pa
        ON p.id = pa.product_id
      where (pa.attribute='min' and pa.value>=5) OR
            (pa.attribute='max' and pa.value<=5)
      group by p.id
      having count(*)=2
    ) s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables like follows: products id | name 1 | name1 2
I have 2 tables like this: Stock Table product_id bigint(20) qty float Sales Table
I have 2 tables set up like this (irrelevant rows omitted): > product -
I have a table products , and I have columns like product_name , product_id
I have an SQL table like this : sales(product,timestamp) I want to display a
hi i have tables like this: Persons: person_id, name then i have many langauge
I have there mysql table: **product (id,name)** 1 Samsung 2 Toshiba 3 Sony **attribute
I have three tables in a database: Product table - +100000 entries Attribute table
I have multiple product tables (not related to each other). All products tables having
I have a table of products with attributes like SKU, Name, etc. It seems

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.