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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:14:05+00:00 2026-05-23T08:14:05+00:00

Hello guys I have a problem with a query and left join I have

  • 0

Hello guys I have a problem with a query and left join

I have 2 tables products and characteristics
I know some required characteristics with id 1,3,6

 SELECT * FROM products
    LEFT JOIN characteristics ...
    WHERE characteristics_id IN (1,2,6)

But this not works for me because I need the products with ALL of this characteristics, not only one.

Really I need

 SELECT * FROM products
    INNER JOIN characteristics as c1 ... AND c1.id=1
    INNER JOIN characteristics as c2 ... AND c2.id=2
    INNER JOIN characteristics as c2 ... AND c2.id=3
...

But it don’t like me, there must be a simpler and efficient

Thank you.

  • 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-23T08:14:05+00:00Added an answer on May 23, 2026 at 8:14 am

    First of all, you don’t need a LEFT JOIN at all.

    Second, your first attempt seems perfectly valid and I think it’s the most efficient (when there are indexes on the tables to be joined). But I’m adding another way (that seems more simple as it has only 1 join).


    Simple (to add more than 3 characteristics):

    SELECT p.*
    FROM products AS p
      INNER JOIN characteristics AS c ON ...
    WHERE c.id IN (1, 3, 6)
    GROUP BY p.id
    HAVING
      COUNT(*) = 3             --- or COUNT(DISTINCT c.id)
                               --- depending on your data
    

    More efficient (in most cases, in other words: test, test and test again in your tables with various sizes and number of ids):

    SELECT p.* 
    FROM products AS p
      INNER JOIN characteristics AS c1 ON ... 
      INNER JOIN characteristics AS c2 ON ... 
      INNER JOIN characteristics AS c3 ON ... 
    WHERE c1.id = 1 
      AND c2.id = 3 
      AND c3.id = 6 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys, I have a general design problem with iPhone application. I want to
Hello guys i have a problem streaming PDF files with php, i'm using this
hello guys i have three server and i mange it from SSH so i
Hello guys i have a little problem i get an error: File C:\Users\kokki\Desktop\gb1\main.py, line
Hello guys i have a problem while trying to use the 'radio' input in
Hello guys I have a problem with my application involving Lucene java library and
Hello guys i have an website online wich access the database. The database access
Hello guys I have a confusing question! If I'm using WCF to create a
Hey guys, I have a problem (again). This time I am trying to use
It's me again guys, I have a small problem: // Create new PDF $pdf

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.