Link to home
Start Free TrialLog in
Avatar of cheryl9063
cheryl9063Flag for United States of America

asked on

Order of Select

Curious. If you select one column but not from the table in your from but the table in your join, does that matter? How does the SQL engine handle this? See below

Select
b.Name Id
  From appointments a
 join names b on a.SomeID=b.SomeID
Where A.SomeID = 5000000
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cheryl9063

ASKER

Not what I'm asking really. A vendor has a query in which the column in the select statement does not pull from the first table(forget the where).  In looking at BOTH queries below. Which would perform better?

Select b.Name Id
  From appointments a
 join names b on a.SomeID=b.SomeID


Select b.Name Id
  From names b
 join appointments a on a.SomeID=b.SomeID
such "simple" query both shall run in the same explain plan, hence in the same performance
Are you sure? If we have 34,000,000 rows and multiple indexes both would perform the same?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes, both would perform the same, normally. as the indexes are "static" (in terms of their existance), the sql engine will first see what indexes are there, which would be the most approriate for the query (checking what you give as input, what it will return as ouput, statistics by the table data and indexes etc, without going into details here), and find for both queries the same explain plan.

please just use the "estimate explain plan" for the 2 queries, it shall show you a graphical display, which should be the same for both. the number of "source records" does not matter.
however, based on server load, if the statistics based on input/ouput data might be very close to some "internal thresholds", your queries might indeed be run differently. but this is very unlikely.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial