April 9, 2008 at 7:50 pm
Hello GS,
I apologize for the late response, I have been piled up big time...:exclamationmark:
I will look over your info tomorrow and respond.
Thank you again for your continued input...
-Roberta-
April 10, 2008 at 12:15 am
I think this is a nice little article illustrating a good, systematic method for attacking complicated queries:
http://weblogs.sqlteam.com/jeffs/archive/2007/04/30/60192.aspx
---------------------------------------
elsasoft.org
April 10, 2008 at 1:47 pm
HI jezemine,
Thank you for the article, it is much closer to the idea that I've been having about "breaking it down" piece by piece.
At this moment, I am going to submit another post titled, "Interpreting the Query."
If you have a moment, please take a look and respond.
In the meantime, I will look over your article more closely, and I'd like to ask you a couple of questions about it.
Talk with you soon....;)
-Roberta-
April 10, 2008 at 2:50 pm
however much I'd like to take credit for that article, it's not mine. 🙂
Jeff Smith wrote it - his blog is very good btw.
---------------------------------------
elsasoft.org
April 11, 2008 at 6:07 am
I have learned that if Gail says it, it must be true.
So when I trip over something she says, I worry that I am misunderstanding something. She said:
"It's not recommended to do joins in the where clause any more. Especially since, in 2005 and higher, the old style outer join (*=) does not work."
The original query used the form FROM tableA,tableB, which yields a cartesian product which gets pruned by the subsequent WHERE clause. (No debate on depreciating the old style outer join notation, and in the case under discussion, as you suggested, an INNER JOIN is clearer.)
But I think the phrase "joins in the where clause" is misleading, the join is being done in the FROM clause.
I find cartesian product joins extremely powerful and useful in many situations, and I don't understand why I should replace one keystroke (",") with 12 (" CROSS JOIN ".) Is the "," construct now being discouraged?
April 11, 2008 at 7:21 am
I wasn't speaking about the occations when yuo need a cross join. If you need a full cartesian product, then just list the tables. Dunno about you though, but I very seldom have a query that it a true cartesian product.
By join, I'm refering to the Limiting of a potential cartesian product by specifying the linking columns.
What I meant is that this style is not recommended any more. Among other reasons, it can get difficult to read and it's all to easy to miss a join.
SELECT Column1, col2, col3
from Table1, table2 -- from clause has no joins. It's a straight list of tables
WHERE Table1.col1 = Table2.col2 -- join is done in the where clause
More encouraged is the following.
SELECT Column1, col2, col3
from Table1 INNER JOIN Table2 ON Table1.col1 = Table2.col2 -- join is explicit on what tables and is in the from clause
Make any sense?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
April 11, 2008 at 8:06 am
"Dunno about you though, but I very seldom have a query that it a true cartesian product."
I have many (well at least some) that are important.
Consider a table of employees e with start dates and end dates. If you need to calculate headcounts on the first of every month for the past 7 years, you build a table d of 84 dates (1/1/2002 ... 12/1/2008), cross join (I'd use a comma) the two tables, in the where clause, specify d.date between e.hireDate and e.lastDate, and use groupby and sum(*) to get the counts.
I would have changed your comments to:
SELECT Column1, col2, col3
from Table1, table2 -- cross join (cartisian product) of tables
WHERE Table1.col1 = Table2.col2 -- select matches of interest
Make any sense?
Understand, but are you suggesting that "," as a join operator is now discouraged?
Thanks for taking your time to contribute!
April 11, 2008 at 8:33 am
Jim Russell (4/11/2008)
Understand, but are you suggesting that "," as a join operator is now discouraged?Thanks for taking your time to contribute!
Actually - it has for some time, since it can lead to ambiguous statements. There is a slow but steady push towards using ANSI notation for joins, since it disambiguates what should be used as part of defining the relation/join, and what should be used to limit rows.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 8 posts - 16 through 22 (of 22 total)
You must be logged in to reply to this topic. Login to reply