与在逗号分隔值中搜索有关
当它是多值时,不会检索数据。
根据 newfurniturey 的回答,您可以使用 find_in_set() 搜索逗号分隔值。
SQLFiddle: http ://sqlfiddle.com/#!2/1f514/1
不幸的是,您需要转换:
in(2,3,9)
至
FIND_IN_SET('2', a.'group') > 0 or FIND_IN_SET('3', a.'group') > 0 or FIND_IN_SET('9', a.'group') > 0
产生一个 SQL:
SELECT a.*,
(select count(*) from f4s56_itcs_fields c where c.fid=a.id) nbfields,
(select b.username from f4s56_users b where a.created_by = b.id) username
FROM f4s56_itcs_forms a
where a.created_by=326
or FIND_IN_SET('2', a.`group`) > 0
or FIND_IN_SET('3', a.`group`) > 0
or FIND_IN_SET('9', a.`group`) > 0;
相关数据:
如果不是上述情况,您的问题可能与数据有关。我已经根据您的查询创建了一个测试模式并返回了结果。
SQLFiddle:http ://sqlfiddle.com/#!2/3763b/1
create table f4s56_itcs_fields
(
field_id int,
field_name varchar(20),
fid int
);
create table f4s56_users
(
id int,
username varchar(100)
);
create table f4s56_itcs_forms
(
id int,
created_by int,
`group` int
);
insert into f4s56_users values (326, 'user_326');
insert into f4s56_users values (327, 'user_327');
insert into f4s56_itcs_fields values (1,'name',1);
insert into f4s56_itcs_fields values (2,'last name',1);
insert into f4s56_itcs_fields values (3,'telephone',1);
insert into f4s56_itcs_forms values (1, 326, 2);
insert into f4s56_itcs_forms values (2, 326, 3);
insert into f4s56_itcs_forms values (2, 326, 9);