如何从同一个表中选择唯一的元组 [英] how to select unique tuples from same table

查看:91
本文介绍了如何从同一个表中选择唯一的元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到所有从

注册(sid *,grade,dname *,cno *, sectno *)

enroll(sid*, grade, dname*, cno*, sectno*)

其中每个部分由(dname *,cno *,sectno *)唯一标识

where each section is uniquely identified by (dname*, cno*, sectno*)

推荐答案

您可以在标识节的列上自行连接,并指定 e1.sid<

You can self join on the columns that identify a section and specify e1.sid < e2.sid to fetch each pair of students only once.

select e1.sid, e2.sid from enroll e1
join enroll e2 on e1.dname = e2.dname
and e1.cno = e2.cno
and e1.secno = e2.sectno
where e1.sid < e2.sid
group by e1.sid, e2.sid
having count(*) > 1

这篇关于如何从同一个表中选择唯一的元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆