tags:

views:

39

answers:

3

I'm about to lose it with this stupid mysql statement. Can anyone please tell me what it wrong with this statement please?

SELECT * FROM contacts 
INNER JOIN ind_categories ON contacts.vendor_id = ind_categories.vendor_id AND ind_categories.category_id = "retail" 
AND WHERE zipcode in ( " 93044,93041,93043 " )
+3  A: 

Try:

SELECT * FROM contacts INNER JOIN ind_categories ON contacts.vendor_id = ind_categories.vendor_id AND ind_categories.category_id = 'retail' WHERE zipcode in 
('93044','93041','93043')

You should not have an AND before your WHERE, each set element in the IN clause needs to be quoted separately (if it's a text column, or not quoted at all if its a number column), and your quotes must be single.

Eric J.
thanks man that was quick. Yeah it works perfectly.
Glad I could help.
Eric J.
+1  A: 

Try:

SELECT * FROM contacts 
INNER JOIN ind_categories 
   ON contacts.vendor_id = ind_categories.vendor_id 
      AND ind_categories.category_id = 'retail'
WHERE zipcode IN ('93044','93041','93043')
Mitch Wheat
+3  A: 
SELECT * FROM contacts 
INNER JOIN ind_categories 
   ON contacts.vendor_id = ind_categories.vendor_id AND ind_categories.category_id = "retail" -- AND   <<< removed !
WHERE zipcode in ('93044' ,'93041' ,'93043' )   -- <<<<  changed the in clause

What was wrong ?

  • extra AND before the WHERE clause: syntactically wrong
  • use of double quotes, whereby string variable require single quotes
  • IN statement, the individual values of the zipcode had to be individually expressed as string, not one big string.
mjv