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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.