Results 1 to 11 of 11
  1. #1
    seen is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2009
    Posts
    12

    SQL JOIN statement

    Hi gurus,

    I have the following statement which works fine in access:

    SELECT table1.test FROM table1 JOIN table2 ON table1.col = table2.col

    I run into a problem when I do the following:



    SELECT a.test FROM table1 AS a JOIN table2 AS b ON a.col = b.col

    It throws a syntax error on the FROM claus.. Can anyone tell me what I'm missing? Thanks..

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you tried:
    SELECT test FROM table1 AS a JOIN table2 AS b ON a.col = b.col

  3. #3
    seen is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    12
    Thanks for the response. I just tried it now; still doesn't work.

    Not sure if it's important to note but the recordset is DAO.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I just took a guess. You are Aliasing and I've not really tried that before. Maybe someone with more experience with SQL will drop by with a suggestion.

  5. #5
    seen is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    12
    Okay.. for anyone else viewing this, I'll also note that the below works:

    SELECT a.test FROM table1 AS a, table2 AS b WHERE a.col = b.col

    The issue is when I try to add in the "JOIN" clause with aliasing everything gets fubar'd.

  6. #6
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    just make it in normal query grid design view

    then if you want the sql - change it to sql view

  7. #7
    seen is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    12
    The issue with using the query design grid is that it avoids the JOIN statement all together and defaults to the old syntax. ie. It'll generate the SQL as I stated in my previous post:

    SELECT a.test FROM table1 AS a, table2 AS b WHERE a.col = b.col

    I suppose it may not be possible to combine both JOIN and aliasing, but I'd like to confirm it's not an option.

  8. #8
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    ?? a query is a query; the design via query grid can't "avoid" a join.

    make it work in query grid design view.....then you'll have the sql that works and can be ported to a vb statement with minimal syntax tweeks.... I do it all the time....

  9. #9
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    let me add - - in some cases it is easier for me to conceive of the query via sql first - - and then I am interested in viewing it in grid view....just to see how it would be set up via grid view...

    and in some cases the query can be so complex there is no grid view possible and Access won't go into grid view it just stays with sql text....

    but you can add the same table twice; it will assign a default aliase that you can change in the sql text later if you want...so alot of queries can be set up in grid view.

  10. #10
    seen is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    12
    Let me clarify...

    The two below statements should do the exact same thing:

    1. SELECT a.test FROM table1 AS a, table2 AS b WHERE a.col = b.col

    2. SELECT a.test FROM table1 AS a INNER JOIN table2 AS b ON a.col = b.col

    However, the 2nd statement does not appear to work in Access. When I use the grid view it will only generate the 1st statement. What I want to know is whether the physical syntax "JOIN" can be incorporated in Access to work with aliasing.

    I appreciate the responses thus far...

  11. #11
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    SELECT table1.test
    FROM table1 INNER JOIN table2 AS b ON table1.col = b.col;

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Join Query?
    By KWarzala in forum Forms
    Replies: 5
    Last Post: 07-29-2014, 02:44 PM
  2. Join Key of table in recordset
    By Rohit0012 in forum Forms
    Replies: 14
    Last Post: 09-24-2011, 09:04 PM
  3. Alternative to Join Property???
    By arthura in forum Queries
    Replies: 1
    Last Post: 05-22-2009, 12:17 AM
  4. Self Join in a Table
    By LornaM in forum Database Design
    Replies: 10
    Last Post: 05-06-2009, 10:29 AM
  5. Update with LEFT JOIN
    By mcarthey in forum Access
    Replies: 1
    Last Post: 08-27-2008, 10:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums