Code Word SQL (5)

Source: Internet
Author: User

  
 
  1. --等值连接
  2. select dname loc empno ename from emp a Dept b where a deptno = b deptno and b deptno = 20
  3. --自连接
  4. Selecta.empno,a.Sal,b.empno,b.ename,b.Sal fromEMP a,EMP Bwherea.Mgr=b.empno anda.ename=' SCOTT ';
  5. --笛卡尔积
  6. Selecta||' + '||b||' = '|| (a+b) as "3*3 addition table" from (SelectRowNum a fromall_objectswhererownum<4), (Selectrownum b fromall_objectswhererownum<4);
  7. --内连接
  8. select empno ename sal Salgrade grade from EMP Salgrade where EMP deptno = 10 and emp sal between Salgrade losal and Salgrade hisal
  9. select empno ename Sal Salgrade grade from emp inner JOIN Salgrade on EMP deptno = 10 and emp sal between Salgrade losal and Salgrade hisal
  10. - -Anti-connection
  11. select * from emp where deptno not in (select deptno from dept where loc in(‘NEW YORK‘, ‘DALLAS‘));
  12. select * from dept where deptno not in (select deptno from emp);
  13. --半连接
  14. select * from emp a where exists ( select 1 Span class= "PLN" > from Dept b where loc = ' NEW YORK ' and a deptno = b deptno
  15. select a.* from emp a, dept b where loc=‘NEW YORK‘ and a.deptno=b.deptno;
  16. select * from dept a where exists ( select 1 Span class= "PLN" > from EMP b where a deptno = b deptno and b sal > 2900
  17. select a .* from dept a EMP b a deptno = b deptno and b sal > 2900
  18. select distinct a.* from dept a , emp b where a.deptno=b.deptno and b.sal>2900;




From for notes (Wiz)

Code Word SQL (5)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.