ANSI和非ANSI联接之间有什么区别,您推荐哪些? [英] What is difference between ANSI and non-ANSI joins, and which do you recommend?

查看:571
本文介绍了ANSI和非ANSI联接之间有什么区别,您推荐哪些?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经在许多网站上找到有关哪个更好的答案,即ANSI或非ANSI语法.这两个查询有什么区别?

I have come across many websites to find the answer about which one is better, ANSI or non- ANSI syntax. What is the difference between these two queries?

select a.name,a.empno,b.loc
from tab a, tab b
where a.deptno=b.deptno(+);

和:

select a.name,a.empno,b.loc
from tab a 
left outer join tab b on a.deptno=b.deptno;

在两种情况下结果都是相同的.第二个查询也更长.哪个更好?

The result is same in both the cases. The second query is also longer. Which one is better?

假设是否基于需要连接它们的条件在上面的查询中添加了另一个表Salgrade? .. 谁能假设一张桌子并给我解释

suppose if we have added another table Salgrade in the above query based on what conditions we need to join them?? .. can any one assume one table and give me explanation

推荐答案

这两种语法通常都可以正常工作,但是如果您尝试添加where条件,您会发现第二个语法更容易理解哪个是联接条件和where子句.

both syntaxes usually work without problems, but if you try to add a where condition you will see that with the second one is much simpler to understand which is the join condition and which is the where clause.

1)

  SELECT a.name,
         a.empno,
         b.loc 
    FROM tab a,
         tab b 
   WHERE a.deptno = b.deptno(+)
     AND a.empno = 190;

2)

         SELECT a.name,
                a.empno,
                b.loc 
           FROM tab a,
LEFT OUTER JOIN tab b 
             ON a.deptno = b.deptno
          WHERE a.empno = 190;

此外,识别外部联接也很容易,并且不要忘记包含(+).总的来说,您可以说这只是一个品味问题,但事实是第二种语法更具可读性,不易出错.

Also, it's much easier to recognize an outer join and do not forget to include the (+). Overall you can say it's just a question of taste, but the truth is that the second syntax is much more readable and less prone to errors.

这篇关于ANSI和非ANSI联接之间有什么区别,您推荐哪些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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