Search code examples
sqloracle11g

what does this error mean "column used in NATURAL join cannot have qualifier"


After executing the code below, i get an ORA-25155 error

SELECT p.prod_id, prod_name, prod_list_price,quantity_sold,cust_last_name
FROM products p NATURAL JOIN sales s NATURAL JOIN customer c
WHERE prod_id = 148;

Solution

  • As suggested on a comment, this ORA-25155 error suggests that you're qualifying the column name "p.prod_id" instead of just "prod_id". That is what is triggering your error.

    Try this fully working SQL Fiddle code. Your query should be:

    SELECT prod_id, prod_name, prod_list_price,quantity_sold,cust_last_name
      FROM products
           NATURAL JOIN sales
           NATURAL JOIN customer
     WHERE prod_id = 148;
    

    A NATURAL JOIN over multiple tables will join one pair of tables, then join the third table to the result and so forth. NATURAL JOIN syntax has no explicit join predicate, so the qualifiers aren't used there.