Results 1 to 11 of 11

Thread: SQL tutorial /website ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    United
    Posts
    202

    SQL tutorial /website ?

    Hi ,

    i was wondering if any one know of any free sql tutorials or quiz website to share as i would like to test mine knowledge ?


    TIA

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: SQL tutorial /website ?

    In the Database FAQ (link below, or via the sticky post at the top of this forum) there are links to a few tutorials.

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL tutorial /website ?

    Show us what you know - post some queries you have developed...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: SQL tutorial /website ?


  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    United
    Posts
    202

    Re: SQL tutorial /website ?

    Quote Originally Posted by szlamany
    Show us what you know - post some queries you have developed...
    Hmm..
    I think mine standard is somewhat around this thread.
    http://www.vbforums.com/showthread.php?t=412595

    But i would have problems with understanding or formulating a query like this without help .
    http://www.vbforums.com/showthread.php?t=413333

    So anyway for me to improve ?

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL tutorial /website ?

    btw - that second link is not going to the right place - but I found it anyway.

    I participated in both those threads with you.

    Here's a neat thread going right now with a complex query - try to absorb what's going on in this one - feel free to post questions in that thread - I'll be monitoring it.

    http://www.vbforums.com/showthread.php?t=415757

    Testing your query as you build it is an important step in understanding the changes you are making. We build all our queries in QUERY ANALYZER and slowly test those queries - adding joins and verifying the affect they have - that's paramount to building a complex query.

    If the query is for an UPDATE or INSERT, having a BEGIN TRAN/ROLLBACK wrapped around it makes great sense for testing.

    But I am unclear what your real goal is? The syntax of SQL is extremely easy - very few keywords to deal with. But the ability to pile them on top of each other is where the power and difficulty is - and that can only be overcome, in my opinion, through practice and patience.

    The second link that Mendhak suggested seems to have some nice tutorials - once you have those under your belt the syntax should be second nature.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    United
    Posts
    202

    Re: SQL tutorial /website ?

    i am kinda of lost when it comes to creating correlated sub-queries and how it actually work or when shld it be used ..

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL tutorial /website ?

    I bought and read a great book - Inside MS SQL Server 2000 by Kalen Delaney...

    This book takes the hood off of the SQL Server engine - and once you truly understand and appreciate how the index leaves work and the data storage is accomplished then when to attack data using JOINS or sub-queries becomes almost second nature.

    What do you mean by correlated sub-queries? Give an example if you can.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    United
    Posts
    202

    Re: SQL tutorial /website ?

    Quote Originally Posted by szlamany
    I bought and read a great book - Inside MS SQL Server 2000 by Kalen Delaney...

    This book takes the hood off of the SQL Server engine - and once you truly understand and appreciate how the index leaves work and the data storage is accomplished then when to attack data using JOINS or sub-queries becomes almost second nature.

    What do you mean by correlated sub-queries? Give an example if you can.
    http://www.vbforums.com/showthread.php?t=413333
    Select RE.No, PR.PersonId, PR.PersonName
    ,RE.Destination
    From Person PR
    Left Join Records RE on RE.PersonId=PR.PersonId
    Where RE.no=(Select Max(RE2.no) From Records RE2
    Where RE2.PersonId=RE.PersonId)

    Something like this ?

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: SQL tutorial /website ?

    I see, well that could be re-written using Group By, like this:
    Code:
    Select Max(RE.No), PR.PersonId, PR.PersonName, RE.Destination
    From Person PR
    Left Join Records RE on RE.PersonId = PR.PersonId
    Group By PR.PersonId, PR.PersonName, RE.Destination
    ..however (and it's a big one), this assumes that the Destination is the same for all rows in the Records table for that person - if not you will get duplicate rows for each different value (each with a different No, as it will be the maximum for that Destination value).

    The sub-query works better in this kind of situation as you want to select multiple values from a row in one of the tables, but only where a certain field (No) has a particular value (the Max for that person). I could be wrong here but I dont think that there is a 'reasonable' way (in terms of speed or complexity), if at all, to do that without a sub-query.

    If you only wanted the value for No (or more fields, but all with an aggregate function like Max), then I would expect a Group By to be more efficient, and a bit easier to read IMO.

  11. #11
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL tutorial /website ?

    I realize that the syntax is outside the norm for a query - but it is simple in that it's just calling the sub-query for each row in the FROM table and in that WHERE clause comparing the RE.NO value to one that is derived from the sub-query.

    That's where the true power comes in though - as that sub-query is free to do whatever kind of select/join/where it wants to!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width