If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Using the IN clause in MySQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-13-04, 11:11
BinaryBoy BinaryBoy is offline
Registered User
 
Join Date: Sep 2003
Location: Tampa Bay, FL
Posts: 6
Using the IN clause in MySQL

For some reason I receive the following error when using the IN clause for a subquery in MySQL but in the documentation it seems to show that I should be able to do this. First, here is the SQL that I'm trying to use:

SELECT * FROM IVPrescriptHdr WHERE PAT_NUMBER IN (SELECT PAT_NUMBER FROM IVPatientsOnly WHERE Phone LIKE '(727)%')

Here is the error message I'm receiving:
Error Code : 1064
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT PAT_NUMBER FROM IVPatientsOnly WHERE Phone LIKE '(727)%'
(0 ms taken)

I can't see anything wrong with the syntax at all in my statement. Can someone please help me with this?
Reply With Quote
  #2 (permalink)  
Old 05-13-04, 12:07
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
What version of mysql are you using? You might not be able to use IN.
Reply With Quote
  #3 (permalink)  
Old 05-13-04, 12:52
BinaryBoy BinaryBoy is offline
Registered User
 
Join Date: Sep 2003
Location: Tampa Bay, FL
Posts: 6
I'm using 4.0.18 (latest stable version) ... The IN clause is supposed to be in this version from what I've seen in the documentation.
Reply With Quote
  #4 (permalink)  
Old 05-14-04, 08:49
BinaryBoy BinaryBoy is offline
Registered User
 
Join Date: Sep 2003
Location: Tampa Bay, FL
Posts: 6
Ignore that... Your right quelphdad...

I have the latest stable version but it's 4.1 where they allowed sub queries... It wasn't the IN clause that was getting me it was the sub query... Doh!
Reply With Quote
  #5 (permalink)  
Old 05-18-04, 14:47
exdter exdter is offline
Registered User
 
Join Date: Aug 2003
Posts: 328
Is that the exact query you are using? If it is, it should be
SELECT PAT_NUMBER FROM IVPatientsOnly WHERE Phone LIKE ('727%')

Last edited by exdter; 05-18-04 at 14:53.
Reply With Quote
  #6 (permalink)  
Old 05-18-04, 21:16
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
Quote:
Is that the exact query you are using? If it is, it should be
SELECT PAT_NUMBER FROM IVPatientsOnly WHERE Phone LIKE ('727%')
that isn't the case where his phone numbers show up as (727)-555-1212, your query won't match what he is looking for.
Reply With Quote
  #7 (permalink)  
Old 05-19-04, 14:06
exdter exdter is offline
Registered User
 
Join Date: Aug 2003
Posts: 328
You are correct. I apologize for not looking at his syntax closer.

Last edited by exdter; 05-20-04 at 11:04.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On