注意: 解答这个问题要求: 用一句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 谢谢各位高人解答!
数据库为oracle,一个表有两个字段id,name,查找所有名字相同的人的信息
例如: 表名为 table
id name
1 a
2 b
3 c
4 d
5 e
6 a
7 b
8 c 谢谢各位高人解答!
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
*/
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
where exists(select * from tb where name=a.name and id<>a.id)请问 exists 是什么意思? (这个问题另外加5分)
我的写法: select a.id, a.name from tb a, tb b where b.name = a.name and b.id != a.id;我的写法和你的有什么不同之处? (这个问题再加10分, 谢谢!)本人一诺千金, 分数说给的一定给请放心!
exists:返回值只有两种,一是真,二就是假;
表示真的时候就值行...