156k views
3 votes
Which of the following is a valid SQL statement?

a. SELECT c.customer#, order#, orderdate, shipdate FROM customers c NATURAL JOIN orders c;
b. SELECT * FROM customers JOIN orders ON (customer#);
c. SELECT c.customer#, order#, orderdate, shipdate FROM customers c, orders c WHERE c.customer# = o.customer#;
d. both b and c

User Sammyukavi
by
5.1k points

1 Answer

4 votes

Answer:

Hi!

The correct answer is B.

Step-by-step explanation:

This sentence SELECT * FROM customers JOIN orders ON (customer#) selects all the columns of both customers and orders and joins by the name of the column customer.

A and B options have syntactic problems:

  • A and C: Same alias name for multiple tables.

  • A and C: Selected columns are ambiguous.

  • C: refers to an alias not declared on the FROM sentence.

a) SELECT c.customer#, order#, orderdate, shipdate(omits aliases) FROM customers c NATURAL JOIN orders c(same aliases definiton);

c) SELECT c.customer#, order#, orderdate, shipdate(omits aliases) FROM customers c, orders c(same aliases definiton) WHERE c.customer# = o.customer#(o not declared);

User Bart Schelkens
by
5.1k points