+ Reply to Thread
Results 1 to 5 of 5

SQL join syntax error

  1. #1
    Registered User
    Join Date
    04-07-2013
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    26

    SQL join syntax error

    Hi



    I am getting a syntax error in FROM clause when I attempt to run some VBA with sql Join.

    I get no errors when attempting simple select queries on either table.



    The tables are as below.



    NameL

    ID NameV Age
    1 Mark 30
    2 George 22
    3 Andrew 20


    NameR

    ID NameW Salary
    1 mark 100000
    2 George 500000
    3 Arnold 50000




    The code is as follows:
    Please Login or Register  to view this content.
    Any ideas as to what I am doing incorrect?



    Both database and excel file with code are attached



    thanks
    Attached Files Attached Files
    Last edited by redmarko; 11-09-2020 at 04:37 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: SQL join syntax error

    You didn't say what result you want so it's a little hard to figure out what is correct.

    I am guessing this:

    Please Login or Register  to view this content.
    This effectively does an inner join.

  3. #3
    Registered User
    Join Date
    04-07-2013
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: SQL join syntax error

    Hi

    Nice alternative but I wanted to figure out the fundamental sql JOIN.

    I eventually got their.

    This worked:
    MyQuery = "Select * FROM NameR Inner Join NameL ON NameL.NameV = NameR.NameW;"

    This didnt:
    MyQuery = "Select * FROM NameR Join NameL ON (NameV=NameW);"


    Unlike true sql you need to be explicit on the join type ie INNER
    You need to call out the tables on the join fields.
    The code works with or without the join types being bracketed

  4. #4
    Registered User
    Join Date
    04-07-2013
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: SQL join syntax error

    Oh by the way OUTER join is not supported by MS access and excel vba
    You have to got left join, right join and union

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: SQL join syntax error

    Thanks for following up with your solution. I have not had much Access experience but am surprised that outer join is not supported. I have used it in Oracle and MySQL and thought it was standard SQL.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Runtime Error '3075': Syntax error in the string in the query expression [SQL]
    By leegrj in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-28-2020, 04:11 PM
  2. Replies: 5
    Last Post: 11-28-2019, 04:55 AM
  3. Why the syntax error with the Join function?
    By Mark43 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2019, 03:09 PM
  4. [SOLVED] Syntax on line continuations around LEFT JOIN
    By ejoneslor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-09-2016, 03:31 AM
  5. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  6. getting an error- a script out of range - Join function
    By AB33 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2012, 01:29 PM
  7. Syntax Error and Compile Error: Expected Line Number or Label...
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2011, 09:59 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1