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

  • Home
  • SEARCH
  • 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 8357939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:38:42+00:00 2026-06-09T10:38:42+00:00

How I can optimize a triple join query like this select users.id_user from users,sales,specSales

  • 0

How I can optimize a triple join query like this

select users.id_user from users,sales,specSales where users.id_user=sales.id_user AND sales.id_sale=specSales.id_sale AND specSales.id_article=34 group by id_user

I want distinct users who bought the product identified by the id_article=X

i’ve thought to this but I’m not secure of the improvement

select id_user from (select distinct(sales.id_user) from sales,specSales where sales.id_sale=specordine.id_sale and specSale.id_article=34)as t

tables are ( *=primary key)

users
*id_user | name | ....

sales
*id_sale | id_user | .... other values

salesSpec
id_sale | id_article | .... other values

Lots of 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-09T10:38:44+00:00Added an answer on June 9, 2026 at 10:38 am

    The second query can be simplified to:

    select distinct(sales.id_user)
    from sales join
         specSales 
         on sales.id_sale=specordine.id_sale
    where specSale.id_article=34
    

    This should perform faster than the first version. One simple reason: it is not joining in the users table. The “distinct” should be about the same amount of work as the “group by”, so the difference in joins should be the dominant effect for performance.

    This assumes that the joining of the users table did not act as a filter (all user ids ain sales are in the table and there are no duplicates).

    Also, you should start using proper join syntax. The use of the “,” in the from statement is bad practice.

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

Sidebar

Related Questions

I would need some help on how to optimize the query. select * from
Just wondering if anyone can optimize this usortMonths() function to be better? Basically I
Can I optimize a Core Data query when searching for matching words in a
Can I optimize the class assignment here at all? I have to do this
How can I optimize below SQL (simplified view of my complex query.) Ideally, I
I have a C++ application that can be simplified to something like this: class
I am wondering if anyone can optimize following code: LOOP AT dispinstock. SELECT matnr
Imagine this code: int foo() { return foo(); } The compiler can optimize this.
I believe I can optimize this sql statement by using a case statement for
I am a little bit puzzled as to how I can optimize my program

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.