Jump to content

Help Please! IN Statement not working


dredge

Recommended Posts

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_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 (

\'1004\'

) AND WC_SSN

IN (

\'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_SSN

FROM WC_Skill

WHERE Skill_ID

IN (

\'1166\', \'1198\', \'1180\'

) 

 

 

SELECT WC_SSN

FROM WC_Certificate

WHERE Certificate_ID

IN (

\'1001\', \'1003\', \'1007\', \'1008\'

) 

 

 

I am using PHP 4.1.2 and MySQL 3.23.39

 

Thanks in advance. : )

Link to comment
https://forums.phpfreaks.com/topic/1216-help-please-in-statement-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.