Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

MySQL problem regarding nested queries (aka. subqueries)

  • 18-02-2002 05:46PM
    #1
    Registered Users, Registered Users 2, Paid Member Posts: 14,174 ✭✭✭✭


    Hey guys,

    having a problem with an sql statement, and I can't see why. It runs under M$ sql and postgres, and the syntax appears to be in accordance with the MySQL documentation, but I can't figure out wtf is wrong with it

    ANy help??

    select month, year, status
    from claimStatus
    where qicID in
    (select qicID
    from QicClaim
    where gmsNum = $gmsNum
    and pwd = '$pwd')

    I keep getting the following error under MySQL whenver I try to execute the command:

    ERROR 1064: You have an error in your SQL syntax near 'select qicID
    from QicClaim
    where gmsNum = 34985
    and pwd = 'ABC123')' at line 3


Comments

  • Registered Users, Registered Users 2 Posts: 2,494 ✭✭✭kayos


    Instead of using the IN Statement try EXISTS

    IE
    select
    	month,
    	year,
    	status 
    from
    	claimStatus 
    where
    	EXISTS
    	(
    	select
    		qicID 
    	from
    		QicClaim 
    	where
    		gmsNum = $gmsNum 
    	and
    		pwd = '$pwd'
    	and
    		QicClaim.qicID = claimStatus.qicID
    	) 
    

    Hopefully that will work for you. If not I'll actually look up stuff on MySQL :)

    kayos


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    What version of MySQL are you running? Only recent versions of MySQL support subselects as far as I know.

    adam


  • Registered Users, Registered Users 2, Paid Member Posts: 14,174 ✭✭✭✭Lemming


    Originally posted by dahamsta
    What version of MySQL are you running? Only recent versions of MySQL support subselects as far as I know.

    adam

    (\s at command line)

    Server version 3.22.32
    Protocol version 10


    and the "exists" keyword doesn't work in place of "in" - DOH!


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    have u tried just
    select qicID
    from QicClaim
    where gmsNum = $gmsNum
    and pwd = '$pwd'
    and see if that works ?


  • Registered Users, Registered Users 2, Paid Member Posts: 14,174 ✭✭✭✭Lemming


    Originally posted by amen
    have u tried just
    select qicID
    from QicClaim
    where gmsNum = $gmsNum
    and pwd = '$pwd'
    and see if that works ?

    Yup. Works fine.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,562 ✭✭✭Snaga


    Hey James,

    try reading through this thread on phpbuilder....

    http://www.phpbuilder.com/forum/read.php3?num=5&id=24660&loc=0&thread=24660

    It comes from a similar angle but may not work depending on the contents of claimstatus.

    Too tired to put much more effort into it tonight ;)


  • Registered Users, Registered Users 2, Paid Member Posts: 14,174 ✭✭✭✭Lemming


    Originally posted by Snaga
    Hey James,

    try reading through this thread on phpbuilder....

    http://www.phpbuilder.com/forum/read.php3?num=5&id=24660&loc=0&thread=24660

    It comes from a similar angle but may not work depending on the contents of claimstatus.

    Too tired to put much more effort into it tonight ;)

    Ta Eric! I'll have a look tomorrow (am just back from the pub .. so needless to say slightly intoxicated ;) )


Advertisement