我需要这样的查询。
Set @var1:="30,31";
Select * from mytable where id in (@var)
我尝试在多个表中进行操作,但MySQL返回了空值。为什么?
Set @var1:="30,31";
Select * from mytable where id in (@var)
我尝试在多个表中进行操作,但MySQL返回了空值。为什么?
WHERE IN
子句是困难的。假设你总是只绑定两个值,我们可以尝试:SET @sql = 'SELECT * FROM mytable WHERE id IN (?, ?)';
PREPARE stmt2 FROM @sql;
SET @var1 = 30;
SET @var2 = 31;
EXECUTE stmt2 USING @var1, @var2;
find_in_set()
来检查这里。SET @var1 = "30,31";
SELECT * FROM mytable WHERE find_in_set(myTable.myColumn, @var1);
MySQL返回NULL
值是因为搜索字符串不是值列表。