我想在单列中通过两个特定名称获取记录,但此查询对我不起作用,
SELECT *
FROM orders_custom oc
INNER JOIN group_options go
ON oc.group_option_id = go.group_option_id
WHERE orderedProduct_id = '40476'
AND go.is_default = 1
AND oc.group_name = 'size'
AND oc.group_name = 'base'
写它的正确方法是什么?
答案 0 :(得分:2)
尝试此查询
SELECT * FROM orders_custom oc
INNER JOIN group_options go ON oc.group_option_id = go.group_option_id
WHERE orderedProduct_id = '40476'
AND go.is_default = 1
AND oc.group_name in ('size','base')
或者您可以在OR
子句
AND (oc.group_name = 'size' OR oc.group_name = 'base' OR ...)
答案 1 :(得分:2)
最后oc.group_name
您应该使用OR
或IN
。
答案 2 :(得分:1)
您需要使用OR
,请参阅以下示例:
SELECT * FROM orders_custom oc
INNER JOIN group_options go
ON oc.group_option_id = go.group_option_id
WHERE orderedProduct_id = '40476' AND go.is_default = 1 AND (oc.group_name = 'size' OR oc.group_name = 'base')