Learning and Understanding SQL

  • I need a good book on SQL, so i can learn different variations for writing queries and know what is the most optimized syntax.

    For example I'm used to the

    Select column

    From table

    Join ... ON

    Where

    But I've seen

    Select column

    From (

            Select

            From

            Where)

    and i don't understand taht syntax and didn't know it could be used or exist. How can you use the From clause to do subqueries? Can multiple columns be used. I ask because multiple columns typically can't be used with the IN operator in WHERE CLAUSE. I had Teach yourself SQL in 24 hours but it was only 89-compliant.

    So, to get an idea of what my options are i would like a good book or website that teaches the lates acceptable syntax.  and teaches about optimization.

    Any thoughts? I would like an explanation for that subquery also.  thanks!

    I have SQL Server2000 bible and Teach yourself SQL Server2000 in 21 days, but i guess i need to know the ins and outs of SQL

  • I swear by Wrox and OReilly publications..

    Here're a few links you could look up:

    http://www.w3schools.com/default.asp

    http://www.mssqlserver.com/tsql/

    http://vyaskn.tripod.com/sqlserverres.htm







    **ASCII stupid question, get a stupid ANSI !!!**

  • Wrox and O'Reilly are definitely good. I would also recommend the Murach's SQL for SQL Server (for beginners). They talk a bit about your example (joins vs subqueries) and what the differences are.

    I think the short answer is that the join (first example you listed) is faster, but you never know when querying live data. Also, sometimes you need correlated subqueries (subquery executes once for each row in the outer query), etc.

    Once you've advanced, The Guru's Guides (by Ken Henderson) are really good, as well as Advanced Transact-SQL for SQL Server (by Ben-Gan and Moran).

  • Ken Henderson's books are probably the one's I've learned the most from. And, yes, I confess, I really, really like "SQL for Smarties" by Joe Celko.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply