Results 1 to 4 of 4
  1. #1
    pasin is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    8

    help with sql quey

    Can somebody help me with below sql query. It is showing an error and probably it is because of brackets. Thanks!


    Error is: Syntax error (missing operator)

    Code:
    select clientt.clientid,loant.loanid
    from (clientt
    inner join loant on clientt.clientid=loant.clientid)
    inner join
    schedulet s1 on loant.loanid=s1.loanid
    left join
    (SELECT pay.loanid,  pay.paiddate FROM paymentt AS pay 
     INNER JOIN (SELECT max(paymentid) AS id FROM paymentt GROUP BY loanid)  AS [max] ON pay.paymentid=max.id) 
     AS t ON t.loanid=s1.loanid

  2. #2
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    Break each bit of it down and see if it runs.
    Check this returns what you expect

    SELECT pay.loanid, pay.paiddate FROM paymentt AS pay
    INNER JOIN (SELECT max(paymentid) AS id FROM paymentt GROUP BY loanid) AS [max] ON pay.paymentid=max.id

    If it does then this might work

    Code:
    SELECT  clientt.clientid,loant.loanid
    FROM clientt
    INNER JOIN loant on clientt.clientid=loant.clientid
    INNER JOIN schedulet s1 on loant.loanid=s1.loanid
    LEFT JOIN (SELECT pay.loanid,  pay.paiddate FROM paymentt AS pay 
    INNER JOIN (SELECT max(paymentid) AS id FROM paymentt GROUP BY loanid)  AS [max] ON pay.paymentid=[max].id) 
     AS t ON t.loanid=s1.loanid
    BTW - Max is a terrible choice of alias. I'm not sure I can think of a worse one other than maybe SELECT
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    I have reformatted Minty's sql using the free PoorSQL

    Code:
    SELECT clientt.clientid
    	,loant.loanid
    FROM clientt
    INNER JOIN loant
    	ON clientt.clientid = loant.clientid
    INNER JOIN schedulet s1
    	ON loant.loanid = s1.loanid
    LEFT JOIN (
    	SELECT pay.loanid
    		,pay.paiddate
    	FROM paymentt AS pay
    	INNER JOIN (
    		SELECT max(paymentid) AS id
    		FROM paymentt
    		GROUP BY loanid
    		) AS [max]
    		ON pay.paymentid = [max].id
    	) AS t
    	ON t.loanid = s1.loanid

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    FYI trouble shooting tip - if you put the query in sql view then attempt to run it and it fails, the cursor usually goes just to the right of the offending part. Sometimes helps to zero in on the offending syntax.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Field selection based on quey results
    By Xarkath in forum Access
    Replies: 1
    Last Post: 06-14-2013, 04:37 PM
  2. Runing a quey in the back end?
    By jbr87 in forum Access
    Replies: 7
    Last Post: 07-25-2011, 08:30 AM
  3. Replies: 0
    Last Post: 01-16-2010, 12:28 AM
  4. Need help with parameter quey
    By toptech in forum Queries
    Replies: 0
    Last Post: 10-22-2009, 05:20 PM

Tags for this Thread

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