8

I am looking at a practice test that doesn't have explanations about the correct answers. The question I'm confused about basically asks why the following SQL statement can never work:

SELECT oi.order_id, product_jd, order_date
FROM order_items oi JOIN orders o
USING(order_id);

The answer it gave was: "The statement would not execute because the column part of the USING clause cannot have a qualifier in the SELECT list"

Can someone elaborate on this? I am pretty stumped.

1 Answer 1

14

It's complaining about the oi qualifier:

SELECT oi.order_id, product_jd, order_date
       ^^^

Oracle does not allow qualifiers in combination with a using join. The clearest way out is using a regular join:

SELECT oi.order_id, product_jd, order_date
FROM order_items oi 
JOIN orders o ON o.order_id = oi.order_id

You can also omit the qualifier. The using statement tells Oracle that even though there are two fields called order_id, they are both equal:

SELECT order_id, product_jd, order_date
FROM order_items oi JOIN orders o
USING(order_id)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.