mysql in和union一起使用查询失败

SELECT * FROM bg_qa where id in (select id from bg_qa where tenant_id=3 and package_id in(0) and status = 1 and category_id in (1,574)
union select belong from bg_qa where tenant_id=3 and package_id in(0) and status = 1 and category_id in (1,574))
上面的语句查询失败

但是单独查询里面的字语句没有问题:
select id from bg_qa where tenant_id=3 and package_id in(0) and status = 1 and category_id in (1,574)
union select belong from bg_qa where tenant_id=3 and package_id in(0) and status = 1 and category_id in (1,574)

SELECT * FROM bg_qa where id in (123,321,0)

下面的语句可以查询到,有大哥解释下为什么吗
SELECT * FROM bg_qa where id in (select id from (select id from bg_qa where tenant_id=3 and package_id in(0) and status = 1 and category_id in (1,574)
union select belong from bg_qa where tenant_id=3 and package_id in(0) and status = 1 and category_id in (1,574) )as abc)

阅读 1.5k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题