IN in NATURAL JOIN help

SELECT name,telephone
FROM Customer where cid IN
(SELECT cid
FROM Order where oid IN
(SELECT oid
FROM OrderDetal where icode IN
(SELECT icode
FROM item where itemName=’Dry Fish 200g’)));
How can I convert this query to Natural join?
Thanks in Advance

Hi,
You can't do that with NATURAL JOIN.
Forget about NATURAL JOIN.  I've never seen it used outside of a texbook (or on a forum like this) for good reasons.  If you add a column to any table, that may change the results of any NATURAL JOIN involving that table.  You don't want to look at all those queries whenever you condiser adding a new column to a table; you don't even want to keep track of which queries you'd have to look at.
Upon sober reflection, I think it might be possible to do this with NATURAL JOIN, depending on how your tables are designed. I can't tell if it's possible or not without seeing the CREATE TABLE statements for all the tables involved, including unique constraints. If it is possible, it would look like this:
SELECT        c.name, c.telephone
FROM          Customer   c
NATURAL JOIN  Orders     o -- ORDER is not a good table name
NATURAL JOIN  OrderDetal od
NATURAL JOIN  Item  i
WHERE         i.ItemName = 'Dry Fish 200g'
Depending on your data, you may need SELECT DISTINCT.
Message was edited by: FrankKulash
NATURAL JOIN is still a bad idea.

Similar Messages

  • How to specify more than Two Tables in NATURAL JOIN

    Hi,
    I am using Oracle9i R-2. I want help in writing a Query using Two Tables in SQL*PLUS. I am using ANSI/ISO Standrard for table-joins:
    select col1, col2, descr
    from tab1 natural join tab2
    There are two columns col1 & col2 is common between thse two tables. So, it will join them and query execute well.
    How can i use 3rd table tab3 in the same way in Natural Join...? If column col1 & col2 is available in tab3 also.
    I tried this way, but it gives me error:
    select col1, col2
    from tab1 natural join tab2 natural join tab3
    Is it possible to specify more than two tables in Natural Join Clause.
    Please check that out & help please. Thanks.
    Regards,
    Kamesh Rastogi

    I do not get an error when I try the same thing on the same version, as demonstrated below. Can you post your table structure and a copy and paste of a run of your actual query with the error that you are receiving?
    scott@ORA92> select banner from v$version
      2  /
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    PL/SQL Release 9.2.0.1.0 - Production
    CORE     9.2.0.1.0     Production
    TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
    NLSRTL Version 9.2.0.1.0 - Production
    scott@ORA92> select * from tab1
      2  /
          COL1       COL2 COL3
             1          1 A
            10         10 B
    scott@ORA92> select * from tab2
      2  /
          COL1       COL2 COL4
             1          1 C
            20         20 D
    scott@ORA92> select * from tab3
      2  /
          COL1       COL2 COL5
             1          1 E
            30         30 F
    scott@ORA92> select col1, col2, col3, col4, col5
      2  from tab1 natural join tab2 natural join tab3
      3  /
          COL1       COL2 COL3 COL4 COL5
             1          1 A    C    E
    scott@ORA92>

  • Equi join v/s natural join

    hi
    i am using oracle 9.0.1.1.1...
    and using hr schema table employees and departments..when i use equi join on both table it return 107 ...when perform natural join it return 32 rows,,i read in books equi and natural join is same ....why both r return diffrent answer...if they r same...

    The following sample data was used:
    WITH emp as
         SELECT 'joe' AS emp, 1 AS dept_id FROM DUAL UNION ALL
         SELECT 'jill' AS emp, 1 AS dept_id FROM DUAL UNION ALL
         SELECT 'jack' AS emp, 1 AS dept_id FROM DUAL UNION ALL
         SELECT 'jane' AS emp, 2 AS dept_id FROM DUAL UNION ALL
         SELECT 'jeb' AS emp, 2 AS dept_id FROM DUAL UNION ALL
         SELECT 'jed' AS emp, 2 AS dept_id FROM DUAL UNION ALL
         SELECT 'joseph' AS emp, 3 AS dept_id FROM DUAL UNION ALL
         SELECT 'jackie' AS emp, 3 AS dept_id FROM DUAL
    dept as
         SELECT 'accounting' as dept_name, 1 as dept_id, 2 as real_dept_id FROM DUAL UNION ALL
         SELECT 'IT' as dept_name, 2 as dept_id, 4 as real_dept_id FROM DUAL UNION ALL
         SELECT 'hr' as dept_name, 3 as dept_id, 6 as real_dept_id FROM DUAL
    )NATURAL JOIN (implicitly joins on dept_id columns because of the same column name):
    SELECT emp,dept_name
    FROM emp NATURAL JOIN dept
    EMP    DEPT_NAME
    joe    accounting
    jill   accounting
    jack   accounting
    jane   IT
    jeb    IT
    jed    IT
    joseph hr
    jackie hrEQUIJOIN, you must specify the columns. In this case if you specify the same join condition the NATURAL JOIN chose you will get the same results:
    SELECT emp,dept_name
    FROM emp JOIN dept ON dept.dept_id = emp.dept_id
    EMP    DEPT_NAME
    joe    accounting
    jill   accounting
    jack   accounting
    jane   IT
    jeb    IT
    jed    IT
    joseph hr
    jackie hrHowever, if the real join column was REAL_DEPT_ID then the NATURAL JOIN cannot satisfy that condition because the column names are different. You would have to use the EQUIJOIN
    SELECT emp,dept_name
    FROM emp JOIN dept ON dept.real_dept_id = emp.dept_id
    EMP    DEPT_NAME
    jane   accounting
    jeb    accounting
    jed    accountingHope this helps!

  • A simple problem with natural join

    i have 2 tables what have columns with distinct's names are referenced.
    natural join not works 'cose only foreign key reference this 2 tables.
    Have something to make table join in using an specific foreign key??
    I'm using oracle9i
    Example:
    table a( a_cod number, a_name varchar2(20))
    table b( b_cod number, b_month_year date, b_salary number)
    ALTER TABLE b ADD ( CONSTRAINT b_a_FK FOREIGN KEY (b_cod)
    REFERENCES a (a_cod));
    select * from a natural join b
    where trunc(b_month_year) = trunc(sysdate)

    I'm not express me correctly.
    We have 2 tables like this:
    CREATE TABLE PPTBA001
      PPA001_GROUP             NUMBER(3)            NOT NULL,
      PPA001_PEOPLECODE        VARCHAR2(20 BYTE)    NOT NULL,
      PPA001_NAME              VARCHAR2(60 BYTE)    NOT NULL,
      PPA001_DATEOFBIRTHDAY    DATE                 NOT NULL);
    CREATE TABLE CLTBA001
      CLA001_GROUP            NUMBER(3)             NOT NULL,
      CLA001_CLIENTCODE       VARCHAR2(20 BYTE)     NOT NULL,
      CLA001_SITUATION        NUMBER(1)             DEFAULT 1);
    SELECT * FROM PPTBA001 NATURAL JOIN CLTBA001;
    ALTER TABLE CLTBA001 ADD (
      CONSTRAINT CLA001_PPAA001_FK1 FOREIGN KEY (CLA001_GROUP, CLA001_CLIENTCODE)
        REFERENCES PPTBA001 (OFA001_GROUP,OFA001_PEOPLECODE));
          the select returns without results. 'cose does not have columns like same name.
    Natural join use a columns with same name. I need something use an foreign key.
    Why?? Now i have a problem .. i need aggregate one more column in primary key
    and i need change all selects that have join with PPTBA001 and put manualy a new column.. if have a other possibility like natural join to using a foreign key to join the selects problems is so more easy to resolve.
    Message was edited by:
    jonas.lima

  • Query based on "NATURAL JOIN" statement of Oracle9i

    I have created following 4 tables
    create table CUST_MASTER
    (CUST_NO NUMBER(3),CUST_NAME VARCHAR2(20),CUST_CITY VARCHAR2(20));
    create table ITEM_MASTER
    (ITEM_NO NUMBER(2),ITEM_NAME VARCHAR2(20),
    PRICE NUMBER(4));
    create table ORDER_HEADER
    ( ORDER_NO NUMBER(4), CUST_NO NUMBER(3));
    create table ORDER_ITEMS
    ( ORDER_NO NUMBER(4), ITEM_NO NUMBER(2), QTY NUMBER(3));
    Based on the above 4 table I have executed the following query.
    select c.cust_no, c.cust_name, c.cust_city, oh.order_no, i.item_no, i.item_name, i.price, oi.qty
    from cust_master c, item_master i, order_header oh, order_items oi
    where c.cust_no = oh.cust_no and oh.order_no = oi.order_no and oi.item_no = i.item_no;
    How should I build similar query in Oracle9i making use of "NATURAL JOIN" statement?

    Hallo,
    yes you are correct.
    From SQL Reference
    NATURAL JOIN The NATURAL keyword indicates that a natural join is being performed. A natural join is based on all columns in the two tables that have the same name. It selects rows from the two tables that have equal values in the relevant columns
    Nothing about foreign keys.
    Test:
    select * from scott.emp natural join scott.dept
        DEPTNO      EMPNO ENAME      JOB               MGR HIREDATE                  SAL       COMM DNAME          LOC         
            20           7369     SMITH          CLERK                7902     17.12.1980            800                    RESEARCH           DALLAS
            30           7499     ALLEN          SALESMAN             7698     20.02.1981           1600            300     SALES              CHICAGO
            30           7521     WARD           SALESMAN             7698     22.02.1981           1250            500     SALES              CHICAGO
            20           7566     JONES          MANAGER              7839     02.04.1981           2975                    RESEARCH           DALLAS
            30           7654     MARTIN         SALESMAN             7698     28.09.1981           1250           1400     SALES              CHICAGO
            30           7698     BLAKE          MANAGER              7839     01.05.1981           2850                    SALES              CHICAGO
            10           7782     CLARK          MANAGER              7839     09.06.1981           2450                    ACCOUNTING         NEW YORK
            20           7788     SCOTT          ANALYST              7566     19.04.1987           3000                    RESEARCH           DALLAS
            10           7839     KING           PRESIDENT                     17.11.1981           5000                    ACCOUNTING         NEW YORK
            30           7844     TURNER         SALESMAN             7698     08.09.1981           1500              0     SALES              CHICAGO
            20           7876     ADAMS          CLERK                7788     23.05.1987           1100                    RESEARCH           DALLAS
            30           7900     JAMES          CLERK                7698     03.12.1981            950                    SALES              CHICAGO
            20           7902     FORD           ANALYST              7566     03.12.1981           3000                    RESEARCH           DALLAS
            10           7934     MILLER         CLERK                7782     23.01.1982           1300                    ACCOUNTING         NEW YORK
    alter table scott.emp drop constraint fk_deptno
    select * from scott.emp natural join scott.dept
        DEPTNO      EMPNO ENAME      JOB               MGR HIREDATE                  SAL       COMM DNAME          LOC         
            20           7369     SMITH          CLERK                7902     17.12.1980            800                    RESEARCH           DALLAS
            30           7499     ALLEN          SALESMAN             7698     20.02.1981           1600            300     SALES              CHICAGO
            30           7521     WARD           SALESMAN             7698     22.02.1981           1250            500     SALES              CHICAGO
            20           7566     JONES          MANAGER              7839     02.04.1981           2975                    RESEARCH           DALLAS
            30           7654     MARTIN         SALESMAN             7698     28.09.1981           1250           1400     SALES              CHICAGO
            30           7698     BLAKE          MANAGER              7839     01.05.1981           2850                    SALES              CHICAGO
            10           7782     CLARK          MANAGER              7839     09.06.1981           2450                    ACCOUNTING         NEW YORK
            20           7788     SCOTT          ANALYST              7566     19.04.1987           3000                    RESEARCH           DALLAS
            10           7839     KING           PRESIDENT                     17.11.1981           5000                    ACCOUNTING         NEW YORK
            30           7844     TURNER         SALESMAN             7698     08.09.1981           1500              0     SALES              CHICAGO
            20           7876     ADAMS          CLERK                7788     23.05.1987           1100                    RESEARCH           DALLAS
            30           7900     JAMES          CLERK                7698     03.12.1981            950                    SALES              CHICAGO
            20           7902     FORD           ANALYST              7566     03.12.1981           3000                    RESEARCH           DALLAS
            10           7934     MILLER         CLERK                7782     23.01.1982           1300                    ACCOUNTING         NEW YORK
    ALTER TABLE scott.emp
    ADD CONSTRAINT fk_deptno FOREIGN KEY (deptno)
    REFERENCES SCOTT.dept (deptno)
    ENABLE NOVALIDATE
    /Regards
    Dmytro Dekhtyaryuk

  • Natural Join multiple tables bug!! SQLPLus 10.1.0.4.2

    SQLPLus 10.1.0.4.2 bug detected!! Who knows how to fix it? Many thanks
    I'm experimenting with natural join and found some really strange behaviour when I tried to combine multiple natural joins.
    I have the following schema:
    Model (ModelID PK, brand, type, year), 49 records
    Car (CarID PK, ModelID FK, OwnerID FK, price) 60 records
    Owner (OwnerID PK, name, adres) 48 records
    The database system is Oracle 10g 64bit on Windows 2003 64bit
    The following query gives me the result I expect (29 records):
    SELECT * FROM Owner NATURAL JOIN Car NATURAL JOIN Model
    WHERE brand='Volkswagen'
    However when I start specifying columns in the select clause the number of records in the result differs depending on the columns I select:
    SELECT OwnerID FROM Owner NATURAL JOIN Car NATURAL JOIN Model
    WHERE brand='Volkswagen'
    --> 1260 records
    SELECT OwnerID, CarID FROM Owner NATURAL JOIN Car NATURAL JOIN Model WHERE brand='Volkswagen'
    --> 1260 records
    SELECT ModelID FROM Owner NATURAL JOIN Car NATURAL JOIN Model
    WHERE brand='Volkswagen'
    --> 29 records (as expected).
    Would this be caused by a bug in Oracle or is there a logical explanation?
    TIA,
    Axel Hallez

    Duplicate thread:
    Natural Join bug!! Is this a sqlplus bug, how to fix it?

  • Join Using vs. Natural Join

    Hi I'm preparing for "Oracle9i: DBA Fundamentals I" exam as well.
    I just don't understand why I get different results with these two queries
    Here I 'm using join
    1 select last_name, department_name
    2 from employees
    3 join departments using (department_id)
    4* where last_name like'H%'
    SQL> /
    LAST_NAME DEPARTMENT_NAME
    Hunold IT
    Himuro Purchasing
    Hall Sales
    Hutton Sales
    Hartstein Marketing
    Higgins Accounting
    but when I use a natural join I get fewer rows:
    SQL> select last_name, department_name
    2 from employees
    3 natural join departments
    4 where last_name like'H%'
    5 /
    LAST_NAME DEPARTMENT_NAME
    Himuro Purchasing
    Hall Sales
    what's the difference between join and natural join?

    A NATURAL JOIN joins the two tables based on columns with the same name. So, in your case, the natural join is equivalent to:
    SQL> SELECT last_name, department_name
      2  from employees JOIN departments using (department_id, manager_id)
      3  WHERE last_name like 'H%'
      4  /
    LAST_NAME                 DEPARTMENT_NAME
    Hall                      Sales
    Himuro                    PurchasingNatural joins are a Bad Thing (tm).
    HTH
    John

  • Natural Join/ Join.....Using

    Hi All,
    Is it possible to use table name or alias to qualify column name when using Natural Join / Join.....Using
    As far as I know we cannot do it. So is the following statement syntatically correct:
    SELECT e.last_name, l.location_id
    FROM employees e JOIN location l
    USING (employee_id);
    Thanks.

    First there is no relation between employees and location ;-)
    Second (as you presumed) you cannot use a qualifier for join columns:
    michaels>  SELECT e.last_name, d.department_id
      FROM employees e JOIN departments d USING (department_id)
    Error at line 1
    ORA-25154: column part of USING clause cannot have qualifierbut with other columns it is ok:
    michaels>  SELECT e.last_name, d.department_name
      FROM employees e JOIN departments d USING (department_id)
    LAST_NAME                 DEPARTMENT_NAME              
    Whalen                    Administration               
    Hartstein                 Marketing                    
    Fay                       Marketing                    
    Raphaely                  Purchasing                   
    106 rows selected.

  • Natural join , join on & join using

    Hi
    I am preparing for the IZO-051 exams .I am totally confused with the concept of joins when answering questions .
    In the Oracle certification book ..HR schema example of employees and departments is given
    While answering the multiple choice questions it is difficult to to choose answer !!
    I wanted to know if *Join using & join on conditions yield the same result in some cases or
    where there are only 1 common column between two tables * ??
    for eg if the same HR schema is to be taken
    QUES: Which sql statement produce the name ,department name & city of all the employees who earn more than 10,000.
    The correct answer given is the query below ..
    I understand the query delivers the needed result ..
    select first_name ,department_name,city
    from employees e
    join departments d
    using(department_id)
    join locations l
    using(location_id)
    where salary > 10000;
    Also the query below gives the same results but this is not the answer???
    select first_name, department_name,city
    from employees e join departments d on (e.department_id= d.department_id)
    join locations l on (d.location_id=l.location_id)
    where salary>10000;
    ALSO is there any efficiency issues related to the queries??

    Hi,
    VANPERSIE wrote:
    Frank Kulash wrote:
    The only thing you really have to know about them is "Don't use them." >Nobody in the real world does.Dear Frank
    You confuse me
    why you said noboby in the real world use them?Obviously, that was hyperbolic. I haven't asked everyone in the world if they use USING or EXISTS.
    I have seen a lot of code, on this forum and elsewhere, written by a large number of people I honestly think that fewer than 1 in 1000 uses either USING or NATURAL JOIN, and it is always in the context of studying for an exam, like you, or trying something the user saw in a book. I have absolutely never seen any production code that used either.
    please I just want to know whyWhy are they not used? They make assumptions about the relationships between tables based entirely on column names. Those assumptions do often not reflect reality. People are liable to name their columns anything, sometimes with very good reasons, that don't match the assumptions made by USING and NATRUAL JOIN.
    NATURAL JOIN is more obviious. It's common to have auditing columns such as created_date or last_modify_user in several tables. No human being would assume that these columns were designed for joining, but that's exactly what NATURAL JOIN assumes.
    USING has the same problem, to a much lesser degree. If you're using 3 tables, and they all have a column named order_id, you can't use order_id to join only 2 of the tables with USING. Also, it reverses the convention of qualifying columns that are used in multiple tables. Many people regulary qualify columns (e.g. <b>d.</b>deptno); personally, I think it's a great programming practice. When you use ON, then you must qualify column names that occur in multiple tables, but when you use USING then you must not qualify the columns that occur in join conditions, but you must qualify other ambiguous columns. Most people find that very conf<b>using</b>.

  • Natural join versus using

    Hi all,
    Could anybody clear my doubt regarding NATURAL and USING join. Can we join two columns in NATURAL join if there data types are different. And in USING also should we have same data type or they can be of different type also. In my case it is according to what we have in the books and in other case it is not.
    Regards
    Harpreet Singh
    Coredatabase Systems

    Hi,
    There are some differences ...
    select a.last_name,b.name,dep_id  -- cannot user qualifier
    from emp a
    inner join dep b using (dep_id);
    that is equal to
         select a.last_name,b.name,a.dep_id -- can use qualifier
         from emp a
         inner join dep b on (a.dep_id = b.dep_id)
         that is equal to
              select a.last_name,b.name,dep_id -- cannot user qualifier
              from emp a
              natural join dep bCheers

  • Natural join--not supported in this technology

    Technology on which natural join is executed doesnt support natural joins.
    the odi version i am usind is 11.1.1.
    Look Up also doesnt seem to work in odi 11.1.1.
    How to use look up in odi 11.1.1.

    HI,
    For lookup you can use Outer join.
    For insert you can use Suppose s1 is source and T1 is Target then you can do S1 left outer join with T1.
    Thanks,
    Lony

  • IN A NATURAL JOIN THE ANSWER QUERY DEPENDS OF PROJECTION ??!!

    Hi,
    Related to this question
    Link: problems with natural join
    Does the answer query depend of projection in a complex NATURAL JOIN query?
    Thanks,
    Ion

    You are most likely encountering this bug:
    Bug 5031632 - Wrong results from NATURAL JOIN, Metalink Note: 5031632.8
    It currently affects all versions of Oracle.
    You can tell something weird is going on by the EXPLAIN PLAN results:
    Query:
    SELECT     *
    FROM     BOOK
    NATURAL JOIN
         AUTHORSHIP
         NATURAL JOIN
              AUTHOR
              NATURAL JOIN
              COUNTRY
    WHERE     COUNTRY.NAMECOUNTRY = 'Canada'
    Explain Plan:
    SQL> /
    PLAN_TABLE_OUTPUT
    Plan hash value: 3878360587
    | Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |      |     1 |    39 |    28   (8)| 00:00:01 |
    |*  1 |  HASH JOIN       |      |     1 |    39 |    28   (8)| 00:00:01 |
    |*  2 |   HASH JOIN      |      |     1 |    29 |    17   (6)| 00:00:01 |
    |*  3 |    HASH JOIN     |      |     1 |    23 |     9  (12)| 00:00:01 |
    |   4 |     VIEW         |      |     2 |    16 |     2   (0)| 00:00:01 |
    |   5 |      UNION-ALL   |      |       |       |            |          |
    |   6 |       FAST DUAL  |      |     1 |       |     2   (0)| 00:00:01 |
    |*  7 |       FILTER     |      |       |       |            |          |
    |   8 |        FAST DUAL |      |     1 |       |     2   (0)| 00:00:01 |
    |   9 |     VIEW         |      |     3 |    45 |     6   (0)| 00:00:01 |
    |  10 |      UNION-ALL   |      |       |       |            |          |
    |  11 |       FAST DUAL  |      |     1 |       |     2   (0)| 00:00:01 |
    |  12 |       FAST DUAL  |      |     1 |       |     2   (0)| 00:00:01 |
    |  13 |       FAST DUAL  |      |     1 |       |     2   (0)| 00:00:01 |
    |  14 |    VIEW          |      |     4 |    24 |     8   (0)| 00:00:01 |
    |  15 |     UNION-ALL    |      |       |       |            |          |
    |  16 |      FAST DUAL   |      |     1 |       |     2   (0)| 00:00:01 |
    |  17 |      FAST DUAL   |      |     1 |       |     2   (0)| 00:00:01 |
    |  18 |      FAST DUAL   |      |     1 |       |     2   (0)| 00:00:01 |
    |  19 |      FAST DUAL   |      |     1 |       |     2   (0)| 00:00:01 |
    |  20 |   VIEW           |      |     5 |    50 |    10   (0)| 00:00:01 |
    |  21 |    UNION-ALL     |      |       |       |            |          |
    |  22 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  23 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  24 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  25 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  26 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("BOOK"."IDBOOK"="AUTHORSHIP"."IDBOOK")
       2 - access("AUTHORSHIP"."IDAUTHOR"="AUTHOR"."IDAUTHOR")
       3 - access("AUTHOR"."IDCOUNTRY"="COUNTRY"."IDCOUNTRY")
       7 - filter(NULL IS NOT NULL)
    Query:
    SELECT     NAMEBOOK
    FROM     BOOK
    NATURAL JOIN
         AUTHORSHIP
         NATURAL JOIN
              AUTHOR
              NATURAL JOIN
              COUNTRY
    WHERE     COUNTRY.NAMECOUNTRY = 'Canada'
    Explain Plan:
    SQL> /
    PLAN_TABLE_OUTPUT
    Plan hash value: 3246924444
    | Id  | Operation             | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |      |     1 |    24 |    27   (4)| 00:00:01 |
    |*  1 |  HASH JOIN            |      |     1 |    24 |    27   (4)| 00:00:01 |
    |   2 |   MERGE JOIN CARTESIAN|      |     1 |    21 |    19   (6)| 00:00:01 |
    |*  3 |    HASH JOIN          |      |     1 |    11 |     9  (12)| 00:00:01 |
    |   4 |     VIEW              |      |     2 |    16 |     2   (0)| 00:00:01 |
    |   5 |      UNION-ALL        |      |       |       |            |          |
    |   6 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |*  7 |       FILTER          |      |       |       |            |          |
    |   8 |        FAST DUAL      |      |     1 |       |     2   (0)| 00:00:01 |
    |   9 |     VIEW              |      |     3 |     9 |     6   (0)| 00:00:01 |
    |  10 |      UNION-ALL        |      |       |       |            |          |
    |  11 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  12 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  13 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  14 |    BUFFER SORT        |      |     5 |    50 |    19   (6)| 00:00:01 |
    |  15 |     VIEW              |      |     5 |    50 |    10   (0)| 00:00:01 |
    |  16 |      UNION-ALL        |      |       |       |            |          |
    |  17 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  18 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  19 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  20 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  21 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  22 |   VIEW                |      |     4 |    12 |     8   (0)| 00:00:01 |
    |  23 |    UNION-ALL          |      |       |       |            |          |
    |  24 |     FAST DUAL         |      |     1 |       |     2   (0)| 00:00:01 |
    |  25 |     FAST DUAL         |      |     1 |       |     2   (0)| 00:00:01 |
    |  26 |     FAST DUAL         |      |     1 |       |     2   (0)| 00:00:01 |
    |  27 |     FAST DUAL         |      |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("BOOK"."IDBOOK"="AUTHORSHIP"."IDBOOK")
       3 - access("AUTHOR"."IDCOUNTRY"="COUNTRY"."IDCOUNTRY")
       7 - filter(NULL IS NOT NULL)
    41 rows selected.There are two major differences in these plans.
    1. The correct result has HASH JOINS. However the incorrect result has a MERGE JOIN CARTESIAN. A cartesian join should not be here as there is no need for one per the table structure and NATURAL JOIN syntax.
    2. There is a filter condition missing in the predicate information session.
    Both #1 and #2 above point to the bug I identified. The current work around us to use the JOIN ... ON syntax.
    HTH!

  • NATURAL JOIN Problem

    Hi,
    After reading about natural join on wikipedia , I have been interested in using this syntax to express equi joins between tables that share some common column names. So I have these 3 tables:
    --Cours (sigle, titre, nbCredits)
    --Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale)
    --Personne (nas, nom, prenom, typPers, matricule, pmatricule)
    When I specify * in the select clause, I only get 3 rows, which makes sense given the restriction I have specified in the where clause. But what I don't understand is that when I replace the * with specific column names, then oracle returns a whole bunch of additional rows that should have been rejected in the where clause. It seems to me Oracle should still only return 3 rows. Does this make sense to anyone? Here is the query I am running:
    SELECT *
    FROM Cours NATURAL JOIN Inscription NATURAL JOIN Personne
    WHERE prenom='John'
    AND nom='Doe'
    AND nbCredits>2
    AND noteFinale<>'F'
    AND noteFinale IS NOT NULL;
    -- 3 rows selected (good)
    SELECT sigle, titre
    FROM Cours NATURAL JOIN Inscription NATURAL JOIN Personne
    WHERE prenom='John'
    AND nom='Doe'
    AND nbCredits>2
    AND noteFinale<>'F'
    AND noteFinale IS NOT NULL;
    -- 80 rows selected (bad)
    Ludovic
    Edited by: user3968717 on Dec 5, 2009 12:41 PM
    Edited by: user3968717 on Dec 5, 2009 12:42 PM

    ok so here is how you can reproduce the problem:
    DROP TABLE Inscription;
    DROP TABLE Cours;
    DROP TABLE Personne;
    --Personne (nas, nom, prenom, typPers, matricule, pmatricule)
    --Personne (123456789, ‘Guertin’, ‘François’, ‘P’, NULL, ‘p900771’)
    CREATE TABLE Personne (
    nas NUMBER(9),
    CONSTRAINT pk_nas
    PRIMARY KEY(nas),
    nom VARCHAR2(100) NOT NULL,
    prenom VARCHAR2(100) NOT NULL,
    typPers CHAR NOT NULL,
    CONSTRAINT check_typepers
    CHECK (typPers IN ('E', 'X', 'P')),
    matricule NUMBER(7) UNIQUE,
    pmatricule VARCHAR2(7) UNIQUE
    --Cours (sigle, titre, nbCredits)
    --Cours (‘INF3303’, ‘Java avancé’, 3)
    CREATE TABLE Cours (
    sigle VARCHAR2(12),
    CONSTRAINT pk_sigle
    PRIMARY KEY(sigle),
    titre VARCHAR2(100) NOT NULL,
    nbCredits NUMBER(2)
    --Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale)
    --Inscription (‘INF1101’, ’08-1’, 1234567, 1, 85, ’B’)
    CREATE TABLE Inscription (
    sigle VARCHAR2(12),
    trim CHAR(4),
    matricule NUMBER(7),
    CONSTRAINT fk_inscription_personne
    FOREIGN KEY(matricule)
    REFERENCES Personne(matricule),
    numSect NUMBER(2) NOT NULL,
    cumulatif NUMBER(5,2),
    CONSTRAINT check_cumulatif
    CHECK (cumulatif BETWEEN 0 AND 20),
    noteFinale VARCHAR2(2),
    CONSTRAINT pk_sigle_trim_matricule
    PRIMARY KEY (sigle, trim, matricule)
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (438183442, 'Ould Bachir', 'Mohamed', 'E', 1194330, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (704839482, 'Ben Ali', 'Guillaume- Alexandre', 'E', 1051001, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (299473563, 'Ouali', 'Lijun', 'E', 1440954, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (528291948, 'Nicolescu', 'Irina', 'E', 1249904, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (406489610, 'Hertrich', 'Basil D.', 'E', 836600, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (538967530, 'Gagnon', 'Jean-Francois', 'E', 862895, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (683587008, 'Capistran', 'Hanifa', 'E', 557177, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (420147705, 'Gélinas', 'Dominique', 'E', 775406, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (547877666, 'Pidgeon', 'Louis-Martin', 'E', 1295394, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (641624707, 'Dubois', 'Walter', 'E', 621940, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (276753600, 'Dupuis', 'Nassim', 'E', 1012940, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (347189227, 'Lévesque', 'Segla', 'E', 1330092, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (771931031, 'Hoang', 'Sylvain', 'E', 845099, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (760952747, 'Deschamps', 'René', 'E', 1095066, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (448428805, 'Desforges', 'Sandrine', 'E', 555402, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (294843128, 'Detuncq', 'Serge', 'E', 1406818, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (510245759, 'Mbassegue', 'J.-P.', 'E', 534725, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (599298612, 'Lefrançois', 'L.''Hocine', 'E', 1497297, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (343687369, 'Mullins', 'Marie-Claude', 'E', 1534079, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (697415856, 'Kashyap', 'Jean-François', 'E', 1009214, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (201038917, 'Ouzineb', 'François', 'E', 593700, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (687370755, 'Farhat', 'Bernard', 'E', 1458644, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (518828231, 'Boudreault', 'Rémi', 'E', 671409, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (520474003, 'Lesage', 'Ion', 'X', NULL, 'p136014');
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (384843784, 'Latreille', 'Patrice', 'E', 611719, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (676878312, 'Imbeau', 'Jean-Charles', 'E', 912927, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (643878433, 'Henri', 'Nassim', 'E', 1185544, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (337901910, 'Lafleur', 'Hamza', 'E', 657154, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (775289961, 'Derome', 'Jean', 'E', 600728, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (740755632, 'Baron', 'Christian', 'E', 1164635, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (540055231, 'Messas', 'Aouni-A', 'E', 1323029, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (296229241, 'Milot', 'Robert', 'E', 1478064, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (761602775, 'Lakis', 'Stéphane', 'E', 1249685, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (490121163, 'Salako', 'Sylvain', 'E', 1268450, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (547485629, 'Wygowski', 'Sébastien', 'E', 772428, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (384542025, 'Lacroix', 'Ralph', 'E', 1384960, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (411088972, 'Dubeau', 'Walter', 'E', 1509165, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (664857491, 'Paraschivoiu', 'Mohamed', 'E', 1001731, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (599119293, 'Gagnon', 'Pierrette', 'E', 1130188, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (626247031, 'Abou-Khalil', 'Mario', 'E', 1520042, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (769101909, 'Lacroix', 'Dina Sandrine', 'E', 1280046, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (750382719, 'Tremblay', 'Pierrette', 'E', 668396, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (328263556, 'Daigneault', 'Pierre', 'E', 1470609, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (619801573, 'Bosisio', 'René', 'E', 1200428, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (371336464, 'Fernandez', 'Samer', 'E', 1117180, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (747655251, 'Bertrand', 'Gérald', 'E', 1270615, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (253548669, 'Bélanger', 'Djebar', 'E', 692265, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (655272366, 'Gagné', 'Raymond', 'E', 984770, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (392982583, 'Lafleur', 'Chahé', 'E', 934101, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (246459235, 'Banville', 'Pierre', 'E', 1525599, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (424729975, 'Paraschivoiu', 'France', 'E', 952338, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (363488896, 'Millette', 'Samer', 'E', 1590893, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (648370940, 'Lejeune', 'Jose', 'E', 748277, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (541639150, 'Daoud', 'Christian', 'E', 1040265, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (645224662, 'Brunet', 'Éric', 'E', 1246886, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (687701963, 'Houde', 'Claude', 'E', 638341, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (512932438, 'Heuzey', 'Jules', 'E', 665428, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (388460612, 'McSorley', 'Patrice', 'E', 549806, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (236153443, 'Bilodeau', 'Thang', 'X', NULL, 'p42803');
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (595724089, 'Ruiz', 'Yvon', 'X', NULL, 'p694058');
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (622802612, 'Srinivasan', 'Bernard', 'E', 936457, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (234299107, 'Cybis', 'Jean-Marc', 'E', 1536823, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (643414695, 'Brochu', 'Claude-Jean', 'E', 1541861, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (311014945, 'Roy', 'Guy', 'E', 1509489, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (729095588, 'Bilodeau', 'Marie-Claude', 'E', 1083588, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (245107290, 'N''Dri', 'Eduardo', 'X', NULL, 'p654662');
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (484560064, 'Carreau', 'Louise', 'E', 605540, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (398475115, 'Bussières', 'Giuliano', 'E', 1161512, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (732507105, 'Robert', 'Bernard', 'E', 650703, NULL);
    INSERT INTO Personne (nas, nom, prenom, typPers, matricule, pmatricule) VALUES (618379982, 'Aubertin', 'Patrice', 'E', 1013940, NULL);
    -- Insere les cours
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('INF4201', 'Les systèmes experts: concepts et réalisation', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('MEC8903', 'Fabrication pièces plastiques par injection', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('PL010', 'Science et ingénierie des polymères', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('CY140', 'Piratage informatique', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('ST201', 'Stage industriel I', 1);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('E-222', 'Éléments de circuits électriques', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('ST102E', 'Stage industriel II - suite', 2);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('MEC8508', 'Développement de produits en envir. virtuel', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('AE3400', 'Commande de vol', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('AE4500', 'Informatique embarquée', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('ST102', 'Stage industriel II', 1);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('MEC6906', 'Stage industriel II', 6);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('MEC8310', 'Projet en environnement virtuel', 6);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('ST101', 'Stage industriel I', 1);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('AE4715', 'Avionique', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('ST101E', 'Stage industriel I - suite', 2);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('CP110', 'Électrotechnique appliquée', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('E-302', 'Distribution électrique', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('E-331', 'Commande et protection', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('PHS8201', 'Optoélectronique', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('CP130', 'Logique', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('CIV1100', 'Relations interPersonne_A08lles', 1);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('ST202', 'Stage industriel II', 1);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('MET8106', 'Énergie électrochimique', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('MEC6905', 'Stage industriel I', 6);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('CP510', 'Projet intégrateur', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('MIN-STO3', 'Préparation et rapport du stage', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('MTH1110', 'Équations différentielles ordinaires', 2);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('MIN-STO2', 'Préparation et rapport du stage', 3);
    INSERT INTO Cours (sigle, titre, nbCredits) VALUES ('CY130', 'Clavardage et communications', 3);
    -- Insere les inscriptions
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MIN-STO2', '07-3', 1051001, 1, 5.6, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8310', '09-2', 555402, 1, 8, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MIN-STO2', '07-1', 1384960, 1, 11.8, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC6905', '09-2', 1164635, 1, 10.4, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('AE3400', '07-1', 1280046, 1, 12.6, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8903', '07-1', 1001731, 1, 9.5, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8903', '06-1', 1509489, 1, 11.8, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8310', '06-3', 1051001, 1, 10.8, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('PHS8201', '08-2', 1384960, 1, 9.8, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MIN-STO2', '07-1', 845099, 1, 10.8, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MTH1110', '07-3', 1497297, 1, 8.3, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('CY130', '09-2', 1534079, 1, 9.9, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('INF4201', '06-1', 748277, 1, 16.2, 'B');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('ST201', '08-3', 668396, 1, 12.9, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MTH1110', '07-3', 593700, 1, 11.6, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MTH1110', '06-1', 1013940, 1, 14.1, 'C');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('CIV1100', '08-1', 555402, 1, 8.1, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('ST201', '09-2', 1384960, 1, 5.5, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('ST201', '09-2', 1051001, 1, 6.6, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('CY130', '06-1', 1246886, 1, 13.4, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('AE4500', '06-3', 555402, 1, 13.7, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('CIV1100', '08-3', 1194330, 1, 7.1, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MTH1110', '06-1', 549806, 1, 7.4, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('PL010', '08-3', 555402, 1, 9, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('PHS8201', '07-1', 1509165, 1, 9.1, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MET8106', '07-1', 1200428, 1, 6.7, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('AE3400', '09-2', 534725, 1, 12.3, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('ST101', '07-1', 650703, 1, 8, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('PHS8201', '07-2', 657154, 1, 7.5, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('CY130', '06-1', 1051001, 1, 7.9, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('AE4500', '06-3', 1509165, 1, 7, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MTH1110', '07-3', 668396, 1, 14.3, 'C');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MET8106', '07-2', 668396, 1, 12.5, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MET8106', '08-3', 934101, 1, 9.5, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8903', '06-1', 1470609, 1, 9.4, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('INF4201', '07-2', 1323029, 1, 9.3, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC6905', '08-3', 1384960, 1, 4.6, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MIN-STO2', '09-3', 665428, 1, NULL, NULL);
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('AE4500', '06-3', 1246886, 1, 9.2, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('CP130', '07-1', 1117180, 1, 7.2, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('PHS8201', '08-2', 1470609, 1, 9.1, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8903', '09-3', 934101, 1, NULL, NULL);
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('ST101', '08-2', 748277, 1, 4.7, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('PL010', '06-3', 1470609, 1, 9, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MET8106', '08-1', 912927, 1, 6.7, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('AE3400', '06-3', 1130188, 1, 7.4, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('INF4201', '06-1', 1001731, 1, 10.7, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('INF4201', '06-1', 621940, 1, 15.7, 'C+');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8310', '06-2', 1117180, 1, 12.5, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('ST201', '09-1', 1012940, 1, 6.9, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MTH1110', '06-3', 692265, 1, 16.7, 'B');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('INF4201', '07-2', 1541861, 1, 7.5, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8903', '07-1', 605540, 1, 12.6, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8508', '09-1', 1458644, 1, 8.4, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('CY130', '06-1', 1470609, 1, 17, 'B+');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8310', '06-2', 934101, 1, 13.3, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MTH1110', '09-3', 1249685, 1, NULL, NULL);
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MIN-STO2', '08-2', 657154, 1, 12, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MIN-STO2', '07-1', 1013940, 1, 14.1, 'C');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC6905', '07-2', 1458644, 1, 11.3, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('ST101', '08-2', 1249904, 1, 5.2, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC6905', '09-3', 657154, 1, NULL, NULL);
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MET8106', '08-3', 1470609, 1, 12.9, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('AE3400', '06-3', 1270615, 1, 11, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('ST101', '07-3', 671409, 1, 10.2, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('INF4201', '09-3', 836600, 1, NULL, NULL);
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MET8106', '08-3', 1534079, 1, 11.9, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MTH1110', '08-3', 1323029, 1, 6.9, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('CIV1100', '08-1', 1012940, 1, 13.2, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MTH1110', '06-3', 1117180, 1, 11, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('ST201', '09-1', 1095066, 1, 8.9, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8903', '08-3', 775406, 1, 6.4, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8310', '06-2', 1280046, 1, 4.8, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8903', '06-1', 1330092, 1, 12, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC6905', '09-2', 593700, 1, 14.7, 'C');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('AE3400', '08-1', 1117180, 1, 5.8, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('INF4201', '06-1', 1478064, 1, 9.5, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('PL010', '08-1', 1384960, 1, 10.2, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('AE3400', '08-1', 1406818, 1, 10.7, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('PL010', '09-2', 638341, 1, 15.1, 'C+');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MIN-STO2', '07-1', 1534079, 1, 7.4, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC6905', '07-3', 1440954, 1, 10.5, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('AE4500', '07-1', 1536823, 1, 4.3, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8310', '06-2', 1295394, 1, 7.1, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('INF4201', '09-2', 1440954, 1, 11.2, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('PL010', '08-3', 1440954, 1, 10, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('PL010', '08-3', 611719, 1, 11.7, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC6905', '09-2', 775406, 1, 6.5, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MTH1110', '06-1', 665428, 1, 10.3, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MET8106', '07-2', 1384960, 1, 5.2, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC6905', '09-2', 772428, 1, 13.3, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('ST201', '06-1', 772428, 1, 14.9, 'C');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MET8106', '09-1', 1295394, 1, 5.6, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8508', '09-2', 934101, 1, 12.5, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('ST101', '07-1', 845099, 1, 12.1, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('ST201', '08-3', 1509165, 1, 6.6, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('AE4715', '06-3', 600728, 1, 12.4, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('INF4201', '09-2', 1013940, 1, 12.2, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('MEC8310', '06-1', 934101, 1, 13.2, 'F');
    INSERT INTO Inscription (sigle, trim, matricule, numSect, cumulatif, noteFinale) VALUES ('CP130', '07-3', 1509489, 1, 6.5, 'F');
    COMMIT;
    The query with * only gives 1 result, which is right, but when I use sigle, titre instead I get 5 extra rows. Why?
    SELECT sigle, titre
    FROM Cours NATURAL JOIN Inscription NATURAL JOIN Personne
    WHERE prenom='Pierre'
    AND nom='Daigneault'
    AND nbCredits>2
    AND noteFinale\<\>'F'
    AND noteFinale IS NOT NULL;
    SIGLE TITRE
    INF4201 Les systèmes experts: concepts et réalisation
    INF4201 Les systèmes experts: concepts et réalisation
    CY130 Clavardage et communications
    MIN-STO2 Préparation et rapport du stage
    MEC6905 Stage industriel I
    PL010 Science et ingénierie des polymères
    6 rows selected
    SELECT *
    FROM Cours NATURAL JOIN Inscription NATURAL JOIN Personne
    WHERE prenom='Pierre'
    AND nom='Daigneault'
    AND nbCredits>2
    AND noteFinale\<\>'F'
    AND noteFinale IS NOT NULL;
    MATRICULE SIGLE TITRE NBCREDITS TRIM NUMSECT CUMULATIF NOTEFINALE NAS NOM PRENOM TYPPERS PMATRICULE
    1470609 CY130 Clavardage et communications 3 06-1 1 17 B+ 328263556 Daigneault Pierre E
    1 rows selected
    Edited by: user3968717 on Dec 5, 2009 3:06 PM
    Edited by: user3968717 on Dec 5, 2009 3:09 PM

  • Why FULL NATURAL JOIN works?

    select * from v$version;
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    Why such constructions are successfully parsed and full/left/right/cross are ignored?
    select * from
    (select 1 a from dual)
    full natural join
    (select 2 a from dual);
    select * from
    (select 1 a from dual)
    left natural join
    (select 2 a from dual);
    select * from
    (select 1 a from dual)
    right natural join
    (select 2 a from dual);
    select * from
    (select 1 a from dual)
    cross natural join
    (select 2 a from dual);
    The same time if we try to alias tables it gets an error:
    select * from
    (select 1 a from dual) t1
    full natural join
    (select 2 a from dual) t2;
    ORA-00905: missing keyword
    00905. 00000 - "missing keyword"
    *Cause:   
    *Action:
    Error at Line: 29 Column: 5
    Edited by: Slobodcicov on Nov 28, 2012 11:46 PM

    Try this..
    select * from
    (select 1 a from dual) t1
    natural full join
    (select 2 a from dual) t2;A
    2
    1
    Cheers,
    Manik.

  • A curious "anomoly" with the NATURAL JOIN  compared to the JOIN USING

    The following query returns what I expect from the HR schema [106 rows]:
    select last_name, department_name from employees JOIN departments USING (department_id);
    However, when I do the full natural join with this, I only get 32 rows.
    select last_name, department_name from employees  NATURAL JOIN departments;
    Is the full NATURAL JOIN not using DEPARTMENT_ID to join on? But if not what else would it use? I just ran into this and am mostly curious as I do not use the natural join syntax in production but instead prefer the JOIN ON.
    Thanks.

    Just expanding on user2361373's point a bit, the EMPLOYEES and DEPARTMENTS table both have a DEPARTMENT_ID column and both have a MANAGER_ID column. So the natural join will join on both columns.
    This is why the natural join is evil and ought never, ever, ever, ever, ever to be used in real production code. It violates fundamental tenants of building maintainable applications because it creates the potential that adding columns to an existing table will cause existing code to return incorrect results. If you decide that you need to add a CREATE_DATE column to a few tables, for example, to track when a row was inserted, suddenly, all your natural joins may decide that they need to add the CREATE_DATE to the list of columns to join on and your app starts behaving incorrectly. Or your initial DEPARTMENTS table doesn't have a MANAGER_ID column and you decide to add that later on-- all the existing natural joins between EMPLOYEE and DEPARTMENT start returning incorrect results.
    Justin

Maybe you are looking for

  • Automate month-end process using BDC OB52

    Hello All, Did anyone work for FI period open/Close automation? OB52 is used for opening and closing of FI posting periods. Did anyone write a BDC for transaction OB52. Thanks in advance Pavan

  • DBMS_FGA doesn't work for insert auditing

    I have a 10.2.0.3 database. I want to auditing the changes on my people table. create table sher.people ( first_name varchar2(50), last_name varchar2(50), sal number, ocupation varchar2(50) begin DBMS_FGA.add_policy( object_schema => 'SHER', object_n

  • Stored Procedure Universe Issues

    Working in version 3.1 SP1 Fix pack 1.8 and created some simple stored procedures to use in the universe and everything worked fine but then due to changing requirements added additional logic to the stored procedures (SQL 2005 database) for the repo

  • Cant open my CR2 raw files in Bridges camera raw

    Please help, I cannot open my raw files from my new 5d mark 3, in cs6 bridge or Ps for that matter, yes I know do an update from help-update and yes ive done this several times telling me im up to date. the downloader reads them and generates a jpeg

  • Can't center  "siteBox"

    Hi, I am new to dreamweaver. I have a template that I am using for my website. I am trying to make the "siteBox" slimmer and centered when it is displayed. I've set the width to 60% but I cannot center it. The "float" option only allows me to align i