就是记录里table1_name 相同的记录只取一条

解决方案 »

  1.   

    select * from table1 as t1 where t1.table1_id=(select max(table1_id) from table1 where table1.table1_id=t1.table1_id)
      

  2.   


    create proc test_qq  as 
    drop table a
    create table a (table1_id int ,table1_name char(20),table1_sex char(4))insert into a
    select 1,'a','男' union all
    select 2,'a','男' union all
    select 3,'a','女' union all
    select 4,'b','女' union all
    select 5,'c','女' union all
    select 6,'c','女'
    select *  from  a as aa
    where table1_id=(select max(table1_id) from  a  where a.table1_name=aa.table1_name )
    order by table1_idgoexec test_qq 
    drop table a
      

  3.   

    select distinct name,
            id,
            sex
    from table1