Results 1 to 8 of 8
  1. #1
    rtcary is offline Advanced Beginner
    Windows XP Access 2002 (version 10.0)
    Join Date
    May 2010
    Posts
    35

    A MySQL query syntax does not work in Access

    I'm trying to move a MySQL DB to Access.

    This MySQL query generates a syntax error:

    SELECT c.CL_ID, c.Busname, c.Contact, c.Addr1, c.Addr2, c.City, c.State, c.Zip, c.Email, c.CL_ChgDate, sp.Lastname, sp.Firstname, a.Description, a.Rate FROM Clients c
    LEFT OUTER JOIN Salespersons sp ON c.SP_ID = sp.SP_ID
    INNER JOIN Ads a ON a.AD_ID = c.AD_ID
    WHERE (a.Description <> 'Unknown')
    ORDER BY c.Busname

    Is it because of the aliases?

    Many thanks...

    Todd

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I think it is a precedence issue. Maybe you can use parenthesis to retrieve the LEFT JOIN prior to the INNER. Or the other way around, depending on your needs.

    Code:
    SELECT c.CL_ID, c.Busname, c.Contact, c.Addr1, c.Addr2, c.City, c.State, c.Zip, c.Email, c.CL_ChgDate, sp.Lastname, sp.Firstname, a.Description, a.Rate 
    FROM
    (Clients c LEFT OUTER JOIN Salespersons sp ON c.SP_ID = sp.SP_ID) 
    INNER JOIN Ads a ON a.AD_ID = c.AD_ID

  3. #3
    rtcary is offline Advanced Beginner
    Windows XP Access 2002 (version 10.0)
    Join Date
    May 2010
    Posts
    35
    Thank you! That did it.

    rtcary

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Cool .....

  5. #5
    rtcary is offline Advanced Beginner
    Windows XP Access 2002 (version 10.0)
    Join Date
    May 2010
    Posts
    35
    To your knowledge, is there some Access documentation that addresses "precedence"? By adding the parentheses to the following query, it works, however without the parentheses, it works in MySQL and SQL Server.

    SELECT c.Busname, c.Contact, c.Addr1, c.Addr2, c.City, c.State, c.Zip, c.Email, c.Phone, sp.Lastname, sp.Firstname, a.Description, a.Rate, s.Pay_recd, s.Pay_amt, s.Pay_note, s.SA_ChgDate
    FROM ((Sales s
    INNER JOIN Clients c ON c.CL_ID = s.CL_ID)
    INNER JOIN Salespersons sp ON sp.SP_ID = c.SP_ID )
    INNER JOIN Ads AS a ON a.AD_ID = c.AD_ID
    ORDER BY c.Busname, sp.Lastname, sp.Firstname

    Thank you,

    /rtc

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Ummm, not anything that I am recalling at the moment. If you want to learn the correct syntax for Access SQL, you will likely have to use the tools provided by Access to create queries. Then, use Transact SQL to see how you can push the limits. I know there are resources out there. For Access queries, I think the best options are some free online reference blogs.

    As for precedence with Access SQL, I think it is the simple fact that you need to be explicit and cannot be implicit, like other RDBMS may allow for. I have always been of the school of thought to add the few extra keystrokes and be explicit with my code. If anything, it will help when you try to understand things when you revisit your work in the coming years.

  7. #7
    rtcary is offline Advanced Beginner
    Windows XP Access 2002 (version 10.0)
    Join Date
    May 2010
    Posts
    35
    Thank you for the thorough answer.

    /rtc

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Of course. Good luck with your project.

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

Similar Threads

  1. Access Query/SQL syntax
    By pdevito3 in forum Access
    Replies: 1
    Last Post: 04-10-2015, 02:10 PM
  2. Replies: 24
    Last Post: 04-02-2015, 07:34 AM
  3. Replies: 4
    Last Post: 12-06-2014, 08:49 PM
  4. MySQL Syntax Error from Query String in VBA
    By raynman1972 in forum Programming
    Replies: 2
    Last Post: 09-17-2012, 05:59 PM
  5. VBA Code To Work With MySQL
    By botts121 in forum Programming
    Replies: 0
    Last Post: 07-08-2009, 08:51 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