mysql 嵌套查询 各位高人大侠们帮帮小弟我吧

来源:百度知道 编辑:UC知道 时间:2024/05/27 08:10:02
select * from mytable where id = in (select id from mytable1 ORDER BY COUNT(id) DESC sum LIMIT 0,10)
由于我嵌套的查询时返回的不是(1,2,3)而是结果集我真不知道怎样写能实现(1,2,3)希望各位大侠帮帮忙吧
现在嵌套查询
select * from mytable where id = in (select id from mytable1 ORDER BY COUNT(id) DESC sum LIMIT 0,4)

我想要的结果就是
select * from mytable where id = in (1,2,3,4)

不懂你真正想要什么样子的结果,你的语句有问题:

第一、ORDER BY 和 LIMIT这些都要放在外查询,放在内查询里面没有实际含义

第二、你没有GROUP分组,ORDER BY里面不应该使用COUNT(ID),而且ORDER BY 的东西必需在SELECT 的后面才行

我把语句修改如下,但是不知道是不是你需要的:

select * from mytable where id = in (select id from mytable1)
ORDER BY id DESC LIMIT 0,10

select * from mytable where id in(select id from mytable1 where id<=4)