Jump to content


Photo

Help Please! IN Statement not working


  • Please log in to reply
1 reply to this topic

#1 dredge

dredge
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 October 2003 - 04:48 PM

Hello, I\'m new to SQL and have run across a problem. First of all, here is the complete SQL code that results in an error:

SELECT WC_First_Name, WC_Last_Name, WC_SSN, WC_Availability_Type      	FROM Worker_Client      WHERE WC_City = \'Sacramento\'      	AND      WC_State = \'CA\'      	AND      WC_HS_Status = 1      	AND      WC_College_Status = 2      	AND      WC_SSN IN(SELECT WC_SSN FROM WC_Skill Where Skill_ID IN(\'1166\',\'1198\',\'1180\'))        	AND      WC_SSN IN(SELECT WC_SSN FROM WC_Certificate Where Certificate_ID IN(\'1001\',\'1003\',\'1007\',\'1008\'))

When I run this code, I get this error:


MySQL said:

You have an error in your SQL syntax near \'SELECT WC_SSN
FROM WC_Skill
WHERE Skill_ID
IN ( \'1166\', \'1198\', \'1180\' ) ) AN\' at line 5



The weird thing is that this code works fine when I exchange the insides of the two IN Statements with a test number like \'1004\'. For example, this code works:

SELECT WC_First_Name, WC_Last_Name, WC_SSN, WC_Availability_TypeFROM Worker_ClientWHERE WC_City = \'Sacramento\' AND WC_State = \'CA\' AND WC_HS_Status = 1 AND WC_College_Status = 2 AND WC_SSNIN (\'1004\') AND WC_SSNIN (\'1004\')



Another weird thing is that the code that I just took out in the previous example runs fine on its own. For example, these two pieces of code (from inside the IN Statements) works just fine by themselves:

SELECT WC_SSNFROM WC_SkillWHERE Skill_IDIN (\'1166\', \'1198\', \'1180\')


SELECT WC_SSNFROM WC_CertificateWHERE Certificate_IDIN (\'1001\', \'1003\', \'1007\', \'1008\')


I am using PHP 4.1.2 and MySQL 3.23.39

Thanks in advance. : )

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 23 October 2003 - 06:30 PM

You need version 4.1 of MySql to be able to use subqueries.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users