MYSQL语句语法错误

时间:2009-09-19 02:40:34

标签: sql mysql

我将要用这个愚蠢的mysql语句丢失它。有人可以告诉我这句话有什么问题吗?

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 个答案:

答案 0 :(得分:3)

尝试:

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

你的WHERE之前不应该有一个AND,IN子句中的每个set元素都需要单独引用(如果它是一个文本列,或者如果它是一个数字列则根本不引用),并且你的引号必须是单个

答案 1 :(得分: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

出了什么问题?

    在WHERE子句之前
  • extra AND :语法错误
  • 使用双引号,其中字符串变量需要单引号
  • IN语句中,zipcode的各个值必须单独表示为字符串,而不是一个大字符串。

答案 2 :(得分:1)

尝试:

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