Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

Query Building Tips (Need Them!) Expand / Collapse
Author
Message
Posted Monday, March 31, 2008 10:08 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, April 11, 2008 1:41 PM
Points: 35, Visits: 36
Hey Gail,

Thanks for the "inside dope." I find what you said to be very interesting.
I have built queries using the ON portion of the syntax, although not often as of yet.
I will keep this info in my bag of tricks.
Also, I realized that since right now I am trying to figure out how to interpret a query piece by piece and then turn it into syntax, I need to submit a different type of post.
It's going to be called "Interpreting the Query" and ask some specific questions about "building" the syntax.
Your WITH CUBE and WITH ROLLUP link was especially helpful as it showed the result set tables and really helped me to "see" the thang.
Pls keep an eye out for the next post, "Interpreting the Query." Thanks!

-Roberta-
Post #477400
Posted Monday, March 31, 2008 10:10 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, April 11, 2008 1:41 PM
Points: 35, Visits: 36
Hello Gail,

I have saved your info for a later date when I'm ready for it.
I am familiar with aliases and derived tables, however, not ready
for prime time yet.
Pls see my other response, gracias.

-RF-
Post #477402
Posted Monday, March 31, 2008 10:56 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, April 11, 2008 1:41 PM
Points: 35, Visits: 36
Hi again,

Jeff's post about CTE's and derived tables got my looking at your post again even thought I'm sending a new post on building queries.
I'd like to tell you what I think you are saying so that I can understand the syntax more clearly. Here goes:

1. Major "Aha" for me on the definition of "alias." I have been very aware of that usage in syntax however did not know it was referred to as alias, e.g.
USE pubs
SELECT p.pub_id, p.pub_name
FROM publishers AS p

2. Derived tables are result sets used as table sources in a query.

And then there's the syntax, nicely built by the way, I understand most of it except, please remind me what this line means:

ON TheTable.Col1 = TheDerivedTable.Col1

Thanks, u rock...

-RF-
Post #477413
Posted Tuesday, April 1, 2008 9:28 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 6:30 AM
Points: 42,764, Visits: 35,859
It specified on what columns the join is done.

Same as for a normal inner/outer join between two tables:
FROM Itable1 INNER JOIN Table2 On Table1.Col1 = Table2.Col2

Just in this case it's a join between a table and a subquery



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #477784
Posted Wednesday, April 9, 2008 7:46 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, April 11, 2008 1:41 PM
Points: 35, Visits: 36
HI,

Sorry for the delayed response, I got piled up. Thanks for the explanation on the "ON" portion of the syntax. I'll keep it in my
stockpile.
I should be posting another syntax question shortly, promise...:D

-RF-
Post #482721
Posted Wednesday, April 9, 2008 7:50 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, April 11, 2008 1:41 PM
Points: 35, Visits: 36
Hello GS,

I apologize for the late response, I have been piled up big time...
I will look over your info tomorrow and respond.
Thank you again for your continued input...

-Roberta-
Post #482722
Posted Thursday, April 10, 2008 12:15 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, October 18, 2013 4:06 PM
Points: 471, Visits: 589
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
Post #482785
Posted Thursday, April 10, 2008 1:47 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, April 11, 2008 1:41 PM
Points: 35, Visits: 36
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-
Post #483276
Posted Thursday, April 10, 2008 2:50 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, October 18, 2013 4:06 PM
Points: 471, Visits: 589
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
Post #483315
Posted Friday, April 11, 2008 6:07 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, July 30, 2010 11:27 AM
Points: 435, Visits: 1,403
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?
Post #483579
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse