0

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 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

3
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.

Comments

1

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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.