我有2個表,t1
和t2
。mysql中的列名--IN子句不起作用
我可以在where子句中使用下面的代碼嗎?
t2.id in (t1.itemOption)
凡itemOption
包含逗號分隔像1,2,3值...
ID爲1或2
我有2個表,t1
和t2
。mysql中的列名--IN子句不起作用
我可以在where子句中使用下面的代碼嗎?
t2.id in (t1.itemOption)
凡itemOption
包含逗號分隔像1,2,3值...
ID爲1或2
請通過嘗試以下
t2.id in(選擇yourcolumn從t1)
FIND_IN_SET(t2.id,t1.itemOption)
如果列itemOption
就像逗號分隔,然後只在的concat柱itemOption
和使用,在FIN_IN_SET
所有的值。
查詢
select * from t1
where FIND_IN_SET
(
t1.id,
(select GROUP_CONCAT(itemOption SEPARATOR ',') from t2)
);
我覺得應該是這樣'中(從t1選擇itemOption)'t2.id。 – Wanderer
所以'itemOption'列是varchar類型的權利? – Wanderer