Mysql中表student_table(id,name,birth,sex),查询name重复的id最大的记录,比如'张三'重复2次,id分别是1、2,则结果是id=2的记录。如下SQL错误的是()?
select t4.*
from (
select t2.*
from
(select name,count(*) as c1 from student_table GROUP BY name having c1 > 1)t1
inner join
(select name, max(id) as id from student_table group by name ) t2
on t1.name = t2.name
)t3
right join
student_table t4
on t3.id = t4.id ;
select t4.*
from (
select t2.*
from
(select name,count(*) as c1 from student_table GROUP BY name having c1 > 1)t1
inner join
(select name, max(id) as id from student_table group by name ) t2
on t1.name = t2.name
)t3
inner join
student_table t4
on t3.id = t4.id ;
select t4.*
from (
select t2.*
from
(select name,count(*) as c1 from student_table GROUP BY name having c1 > 1)t1
inner join
(select name, max(id) as id from student_table group by name ) t2
on t1.name = t2.name
)t3
left join
student_table t4
on t3.id = t4.id ;
select t4.*
from (
select t2.*
from
(select name,count(*) as c1 from student_table GROUP BY name having c1 > 1)t1
left join
(select name, max(id) as id from student_table group by name ) t2
on t1.name = t2.name
)t3
left join
student_table t4
on t3.id = t4.id ;