" AND ..和......之间的差异和#34;和"和(和......和)"

时间:2017-10-13 03:12:58

标签: sql oracle oracle11g

我有两个用于oracle 11gr2的语句sql

SQL1:

Select * from tableA inpt, tableB ptbs
where inpt.z='A'
AND (inpt.pid    = ptbs.pid
     AND  inpt.instcd = ptbs.instcd);

SQL2:

Select * from tableA inpt, tableB ptbs
where inpt.z='A'
AND inpt.pid    = ptbs.pid
     AND  inpt.instcd = ptbs.instcd

Sql1比sql2快吗?

写作... and ... and ... and ...慢慢写and (... and ... and (... and ... and ...))

类似于"或"?

2 个答案:

答案 0 :(得分:1)

这里没有区别。

 where inpt.z='A'
    AND (inpt.pid    = ptbs.pid
         AND  inpt.instcd = ptbs.instcd);

where inpt.z='A'
AND inpt.pid    = ptbs.pid
     AND  inpt.instcd = ptbs.instcd

where inpt.pid    = ptbs.pid
     AND  inpt.instcd = ptbs.instcd and inpt.z='A'

一切都是一样的。

答案 1 :(得分:0)

它可能只是写成:

SELECT *
FROM tableA inpt
INNER JOIN tableB ptbs
ON inpt.pid = ptbs.pid
WHERE inpt.instcd = ptbs.instcd
AND inpt.z = 'A'

这可能值得一看:INNER JOIN ON vs WHERE clause