Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot have a qualifier in the select list while performing a JOIN w/ USING keyword

Tags:

sql

join

using

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.

like image 543
JuiceBerry123 Avatar asked May 23 '10 03:05

JuiceBerry123


1 Answers

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)
like image 142
Andomar Avatar answered Oct 22 '22 21:10

Andomar