Results 1 to 7 of 7

Thread: SQL Query With Multiple Inner Joins

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    Ontario, Canada.
    Posts
    85

    Angry

    What I would like to do is create an sql statement that grabs data from multiple tables, that are related by different id fields.
    This is what I have tried:

    "SELECT * FROM [SCHEDULE] INNER JOIN [CLIENTS] ON " & _
    "[SCHEDULE].[CLIREF] = [CLIENTS].[CLIREF] AND " & _
    "INNER JOIN [EMPLOYEES] ON [SCHEDULE].[EMPREF] = " & _
    "[EMPLOYEES].[EMPREF]"

    What I have is a schedule table that links both clients and
    employees together based upon their reference fields. I need to be able to select information from the client,employee and schedule table. I think I just have the sql syntax wrong, but I can't figure it out.

    Any suggestions????


  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    This would be equivalent:


    "Select * from Schedule s, clients c, employees e where e.cliref=c.cliref and e.empref=s.empref"

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    Ontario, Canada.
    Posts
    85

    Talking

    Thanks I already had this, but I wasn't sure if using the INNER JOINS was a better idea. My Schedule table will contain a lot of records, 100000++ and I wasn't sure if the INNER JOINS would produce faster records or not.

    Any ideas on that????

    Thanks in advance.


  4. #4
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Technically, the sql I gave you is an inner join, just old style format.

    The only thing that would make this faster was if you were able to create a view, which would make the structure, more or less, permanent. Of course, you cant create a view in Access...

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    Ontario, Canada.
    Posts
    85

    Cool

    JHausmann thanks for all your advice. The Select Statement seems to be fast enough anyway, I'm also going to set the caching size so that when I show the recordset in the grid that it only brings so many records anyway.

    Thanks again.



  6. #6
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    just so you guys know, the "old style" joins are what is required by ADO if you are to update joined recordsets...if you use INNER JOIN in your SQL Query, ADO is unable to update your joined recordset, it will give you the nasty "insufficient base table information for updating or refreshing...."

  7. #7
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    If you want to make the statement as fast as possible you have to make sure that the fields that are linked between the tables are in fact primary keys.

    What this does is allows you to link on these keys instead of having to "tablescan". You would find this out if you did any query planning for the SQL Statement.

    If you are using something like ADO, and you know that the only values you are returning from the query are PART of the primary keys the you can use the "adKeySet" which will make the statement faster because it doesn't go to the actual tables to get the data but instead pulls them straight from the Indexes saving itself the time to have to then reference the table afterwards... but this is rare.

    If you are using SQL Server 6.5 then I would go to the ISQL window and change the option to produce a query plan... then run the query and look to see if you find the word "tablescan". If you do then it could be made quicker with a few indexes :-)

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