似乎您想要OR
或使用IN
声明。
SELECT i.id
FROM items as i
INNER JOIN items_options as io
ON i.item_id = i.id
WHERE io.option_id IN (60143, 60142)
ORDER BY i.xy ASC
LIMIT 0,50
或者
SELECT i.id
FROM items as i
INNER JOIN items_options as io
ON i.item_id = i.id
WHERE io.option_id = 60143 OR io.option_id = 60142
ORDER BY i.xy ASC
LIMIT 0,50
你不能有一个option_id
同时具有这两个值的。
编辑:如果你想要两个值,你可以使用UNION ALL
查询:
SELECT x.id
FROM
(
SELECT i.id, i.xy
FROM items as i
INNER JOIN items_options as io
ON i.item_id = i.id
WHERE io.option_id = 60143
UNION ALL
SELECT i.id, i.xy
FROM items as i
INNER JOIN items_options as io
ON i.item_id = i.id
WHERE io.option_id = 60142
) x
ORDER BY i.xy ASC
LIMIT 0,50
或者您可以尝试加入items_options
桌面两次:
SELECT i.id
FROM items as i
INNER JOIN items_options as io1
ON i.item_id = io1.id
INNER JOIN items_options as io2
ON i.item_id = io2.id
WHERE io1.option_id = 60143 AND io2.option_id = 60142
ORDER BY i.xy ASC
LIMIT 0,50