0
id name role test
------ -------- -------- --------
1 Name 1 Role 1 1,2
2 Name 10 Role 10 3
3 Name 100 Role 100 4
4 Name 11 Role 11 5,6
SET @val_find := '';
SELECT @val_find := test FROM `users` WHERE `users`.`role`= 'role 11';
SELECT @val_find AS test;
生成以下的輸出:5,6逗號分隔的外鍵
它的工作很好,當我寫:
SELECT * FROM `users` WHERE `users`.`id` IN (5,6)
爲什麼不是在這種情況下工作嗎?
SET @val_find := '';
SELECT @val_find := test FROM `users` WHERE `users`.`role`= 'role 11';
SELECT @val_find AS test;
SELECT * FROM `users` WHERE `users`.`id` IN (SELECT @val_find)
感謝@Gordon Linoff其工作正常,但我只是想知道,爲什麼在那種情況下didn't工作?做u有什麼想法?而其結果類似於搜索所需的結果(5,6) – 2014-11-05 06:36:40
由於您的查詢是'users.id IN('5,6')',它與'users.id ='5,6'' 。 – 2014-11-05 12:42:22