这里分三种情况来介绍
1、in 后面是记录集,如:
select  *  from  table  where   uname  in(select  uname  from  user);
$sql .= " AND a.ID in(select NUTRITIONIST_ID from " . NUTR_DIRECT . " where direct_id ='{$_GET[select_dir]}') ";
2、in 后面是字符串,如:
select  *  from  table  where   uname  in('aaa',bbb','ccc','ddd','eee',ffff'');
注意:这里一定要将字符串用单引号'' 标注起来;
3、in 后面是数组,用如下方法,请参考:
//$pieces是含数据的数组
for($i=0;$i
$uname=$uname."'".$pieces[$i]."',";
}
$the_uname ="uname in(".$uname."'')";
select  *  from  table  where    ".$the_uname." ;
备注:这种方法的原理其实很简单,二就是把数组编程上面“第2种情况”的形式
举例:
SELECT
a.ID,
a. NAME,
a.PROFESSION,
a.CREATE_TIME,
group_concat(c. NAME ORDER BY b.priority) direction,
m. NAME,
m.mobile,
am.EMID
FROM
APP_NUTRITIONIST AS a
LEFT JOIN mallbuilder_member AS m ON a.id = m.userid
LEFT JOIN APP_MEMBER AS am ON am.ID = m.userid
LEFT JOIN APP_NUTRITIONIST_DIRECT AS b ON a.id = b.NUTRITIONIST_ID
LEFT JOIN APP_DIRECT AS c ON b.DIRECT_ID = c.ID
WHERE
a.DELETE_MARK = 'N'
AND a.ID IN (
SELECT
NUTRITIONIST_ID
FROM
APP_NUTRITIONIST_DIRECT
WHERE
direct_id = '200'
)
GROUP BY
a.id
ORDER BY
a.CREATE_TIME DESC