mysql In 查询 得不到想要的结果

sql1 = select code from table A where id=xxxxx; 得到结果 11,22
sql2 = select * from table B where code in (11,22) ; 得到1条结果
然后我写了组合查询如下:
sql3 = select id from table B where code in (select code from table A where id=xxxxx) ;
为什么sql3得不到结果?是哪里的问题呢?想不通

应该和子查询里的重名列有关。
试试把列的table名都标出来。
select id from B where code in (select A.code from A where A.id=xxxxx)
应该就没问题了。还不行的话,干脆
select B.id from B where B.code in (select A.code from A where A.id=xxxxx)
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-11-22
语句没有问题,这么写试一下 select B.id from table B,table A where A.id='' and A.code=B.code ,如果也查询不到数据,查看一下表中的数据吧
第2个回答  2017-11-22
检查
select code from table A where id=xxxxx 的结果到底是什么值啊!