SELECT queries

  • Why is it necessary to sometimes include multiple tables in our SELECT queries?

  • Because the data that your require is located in seperate tables. So you join them together using primary keys and foreign keys to select the information you need.

  • Because sometimes the data you want does not lie in just one table and you have to query all the required tables at the same time in order to get the right data the right way.

    oops, I guess I should have refreshed the web page before posting. I didn't notice that Steve had already answered.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • an example would be something like this

    table1(iUserID, FirstName, LastName)

    1,Jon,Smith

    2,Jim,Smith

    table2(iUserID,Address)

    1,1234 Mocking bird ln

    2,2345 Baltic ave

    if you want to 'link' the two tables together to see who has what address

    select t1.FirstName, t1.LastName, t2.Address

    from table1 t1

    inner join table2 t2 on t1.iUserID = t2.iUserID

    and you get

    Jon Smith 1234 Mocking bird ln

    Jim Smith 2345 Baltic ave

    as a result

  • Thanks Steve for taking out the time to reply to my post.

  • Thanks Alvin for the reply.

Viewing 6 posts - 1 through 5 (of 5 total)

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