Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Thank you again! I can't tell you how much I and my company appreciate what you've done! I love this place!..."

Geography

Where in the world do Tek-Tips members come from?
RHelman (Programmer)
6 Aug 12 12:02
Hello,
I have a query where I am essentially Summing the total cost of each order by customer. I have several tables: Customers, Orders, OrderedUpgrades, Upgrades; each with foreign keys linking them.

I have two SQL queries that work, my question is, which is more efficient and is it preferable to use one format over another? Essentially, one uses the INNER JOIN command while the other does not.

Query 1:

CODE -->

SELECT Customers.ID, Customers.FirstName, Customers.LastName, SUM(OrderedUpgrades.Quantity*Upgrades.Cost) As Total
FROM (((Customers INNER JOIN Orders ON Customers.ID = Orders.Customer) INNER JOIN OrderedUpgrades ON Orders.ID = OrderedUpgrades.Order) INNER JOIN Upgrades ON Upgrades.ID = OrderedUpgrades.Upgrade) GROUP BY Customers.ID, Customers.FirstName, Customers.LastName; 

Query 2:

CODE -->

SELECT Customers.ID, Customers.FirstName, Customers.LastName, SUM(OrderedUpgrades.Quantity*Upgrades.Cost) As Total FROM Customers, Orders, OrderedUpgrades, Upgrades WHERE
Customers.ID = Orders.Customer AND Orders.ID = OrderedUpgrades.Order AND OrderedUpgrades.Upgrade = Upgrades.ID GROUP BY Customers.ID, Customers.FirstName, Customers.LastName; 
PHV (MIS)
6 Aug 12 12:10
IMHO, inner joins are better than filtered cartesian products.

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close