在Oracle Database 12c中用OUTER JOIN替换NOT IN

时间:2017-08-05 17:47:27

标签: sql oracle12c outer-join

在下面描述的场景中,以下两个查询实现了相同的结果: “我想从名为PRODUCT的表格中选择所有未出现在名为PC的单独表格中的模型” 这可以通过以下代码完成:

<div id="wrapper">

  <h1>The Diabetes Risk Assesment Tool</h1>
  <div id="Options">
    <form id="form">
      <p> How old are you? </p>
      1-25 <input type="radio" name="age" value="0" checked> 26-40 <input type="radio" name="age" value="5"> 41-60 <input type="radio" name="age" value="8"> 60+ <input type="radio" name="age" value="10">

      <p> What is your BMI? </p>

      0-25 <input type="radio" name="bmi" value="0" checked> 26-30 <input type="radio" name="bmi" value="0"> 31-35 <input type="radio" name="bmi" value="9"> 35+ <input type="radio" name="bmi" value="10">

      <p> Does anybody in your family have diabetes? </p>

      No <input type="radio" name="diabetes" value="0" checked> Grandparent <input type="radio" name="diabetes" value="7"> Sibling <input type="radio" name="diabetes" value="15"> Parent <input type="radio" name="diabetes" value="15">


      <p> How would you describe your diet? </p>

      Low sugar <input type="radio" name="diet" value="0" checked> Normal sugar <input type="radio" name="diet" value="0"> Quite high sugar <input type="radio" name="diet" value="7"> High sugar <input type="radio" name="diet" value="10">


      <input type="submit" id="calculate" name="button_calculate" value="Calculate">
    </form>
  </div>
</div>

这也可以通过使用OUTER JOIN来实现:

select model
from product
where model not in(
select model from pc);

看到这两个查询获得相同的结果,是否优于另一个?使用OUTER JOIN代替NOT IN是否有任何优势?

1 个答案:

答案 0 :(得分:0)