我在下面给出查询时使用以下内容:
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'
答案 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'
)