Mysql选择查询问题

时间:2010-06-25 13:08:55

标签: mysql sql mysql-error-1054

我在下面给出查询时使用以下内容:

SELECT o.orders_id, o.customers_name, o.customers_id, o.payment_method, o.google_order_id, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name
FROM orders o, orders_status s, customers c
WHERE o.customers_id = c.customers_id
AND o.orders_status = s.orders_status_id
AND c.customers_firstname = Nisha
OR c.customers_lastname = Nisha
OR c.customers_email_address = Nisha
OR c.customers_telephone = Nisha

它给我的错误为:#1054 - Unknown column 'Nisha' in 'where clause'

是的,是吗?有人可以指导我解决这个问题吗?

1 个答案:

答案 0 :(得分:6)

看起来你只需要用引号括起Nisha:'Nisha'

...
AND c.customers_firstname = 'Nisha'
OR c.customers_lastname = 'Nisha'
OR c.customers_email_address = 'Nisha'
OR c.customers_telephone = 'Nisha'

此外,虽然与此错误无关,但请注意,您应该在括号中对AND/OR条件的WHERE条件进行分组:

WHERE (  o.customers_id = c.customers_id AND
         o.orders_status = s.orders_status_id
      ) AND
      (
         c.customers_firstname = 'Nisha' OR
         c.customers_lastname = 'Nisha' OR
         c.customers_email_address = 'Nisha' OR
         c.customers_telephone = 'Nisha'
      )