0

我正在使用以下给定的查询:

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'

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

4

1 回答 1

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'
      )
于 2010-06-25T13:10:35.230 回答