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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:47:16+00:00 2026-06-06T03:47:16+00:00

I have 3 tables which need to be linked in an SQL statement (I’m

  • 0

I have 3 tables which need to be linked in an SQL statement (I’m using PHP – MySQL if it helps). I need to extract all orders where the vendor field from the third table equals ‘3’, as below:

orders   -  orders_items - items

order_id -> order_id
            item_id     -> id
                           vendor = '3'

There are many ways to do this I believe with various WHERE and JOINS but I’m asking for the most efficient methods in comparison to my method below:

SELECT
    orders.order_id
FROM
    items, orders
INNER JOIN
    orders_items
ON
    orders.order_id = orders_items.order_id
WHERE
    orders_items.item_id = items.id
AND
    items.vendor = '3'
GROUP BY
    orders.order_id
  • 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-06T03:47:18+00:00Added an answer on June 6, 2026 at 3:47 am

    Using , notation is not universally considered bad practice, but I think it’s quite a minority now that agree with it. Even Oracle (whose users seems to be the most vocal supporters of that syntax) recommend to not use it.

    But I don’t know anyone who would support mixing , and ANSI-92’s JOIN syntax. It’s just asking for trouble.

    SELECT
      orders.order_id
    FROM 
      orders
    INNER JOIN
      orders_items
        ON orders.order_id = orders_items.order_id
    INNER JOIN
      items
        ON orders_items.item_id = items.id
    WHERE
      items.vendor = '3'
    GROUP BY
      orders.order_id
    

    The SQL Optimiser doesn’t execute that exactly as you specified it. SQL is just a expression from which the SQL Optimiser derives a plan to give a result that fits. By writing it as above the optimiser will find what it sees as the best order to filter, join, sort, etc, and which are the best indexes, etc to use to do those things.

    EDIT

    I’ve noticed people supporting DISTINCT over GROUP BY.

    While DISTINCT is slightly shorter, it is not any quicker, and does place restrictions on you. You can’t later add COUNT(*) for example, but with GROUP BY you can.

    In short, GROUP BY can do anything DISTINCT can, but that’s not true the other way around. I only use DISTINCT in very trivial pieces of code so I can get a shole query on one line. Even then I often later regret it a little as the code develops and I need to rever to GROUP BY.

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

Sidebar

Related Questions

i have two mysql tables which are linked together and i need to show
I need help in writing queries which will update MySql tables from SQL server.
I have two different tables from which I need to pull data blogs which
We have this current database which we need to replace some tables by anther
I have xpath page.search(//table[@class='campaign']//table) which returns two tables. I need to choose only first
I have table which contains double values stored in mysql database ...I need to
I have an SQLAlchemy ORM class, linked to MySQL, which works great at saving
I have an mdb which used to contain a bunch of linked tables. These
I have a two tables which are linked by a one-to-many relationship. Now I
I have a table in which I need both the values to be primary

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.