注意: 解答这个问题要求: 用一句SQL语句完成, 必须用子查询完成, 而且不充许用group by和 having
数据库为oracle,一个表有两个字段id,name,查找所有名字相同的人的信息 
例如: 表名为 table 
id name 
1  a 
2  b 
3  c 
4  d 
5  e 
6  a 
7  b 
8  c 谢谢各位高人解答!

解决方案 »

  1.   

    create table [table](id int,[name] varchar(10))
    insert into [table] select 1,'a' 
    insert into [table] select 2,'b' 
    insert into [table] select 3,'c' 
    insert into [table] select 4,'d' 
    insert into [table] select 5,'e' 
    insert into [table] select 6,'a' 
    insert into [table] select 7,'b' 
    insert into [table] select 8,'c' 
    select * from [table] a where exists (select 1 from [table] where id<>a.id and [name]=a.[name])
    go
    drop table [table]
    /*
    id          name
    ----------- ----------
    1           a
    2           b
    3           c
    6           a
    7           b
    8           c
    */
      

  2.   


    select * from tb a
    where exists(select * from tb where name=a.name and id<>a.id)1 a
    2 b
    3 c
    6 a
    7 b
    8 c
      

  3.   

    lkd twg ftjg r rjuk.
      

  4.   

    select * from tb a
    where exists(select * from tb where name=a.name and id<>a.id)请问 exists 是什么意思? (这个问题另外加5分)
      

  5.   

    从表中查询满足条件的记录, select * from tb a 这个条件是能从表中查到另一条记录( id 不同),它的name和现在查到的那条相同(name相同).不就是查到 name 重复的记录了嘛.
      

  6.   

    qianjin036 谢谢你的再次解答~!在你的基础上, 我自已又想了一种方法, 结果正确! 但从专业角度来讲, 你的方法好还是我的方法好? 请赐教:
    我的写法: select a.id, a.name from tb a, tb b where b.name = a.name and b.id != a.id;我的写法和你的有什么不同之处? (这个问题再加10分, 谢谢!)本人一诺千金, 分数说给的一定给请放心!
      

  7.   


    exists:返回值只有两种,一是真,二就是假;
    表示真的时候就值行...