200k views
4 votes
Which of the following SQL statements will list the name of each customer stored in the CUSTOMERS table, and, if the customer has placed an order that is contained in the ORDERS table, the order# of any order each customer has placed?

a. SELECT lastname, firstname, order# FROM customers NATURAL JOIN orders;
b. SELECT lastname, firstname, order# FROM customers c LEFT OUTER JOIN orders o ON c.customer# = o.customer#;
c. SELECT lastname, firstname, order# FROM customers RIGHT OUTER JOIN orders;
d. SELECT lastname, firstname, order# FROM customers JOIN orders USING (customer#);

1 Answer

5 votes

Final answer:

The correct answer is option b). SELECT lastname, firstname, order# FROM customers LEFT OUTER JOIN orders o ON c.customer# = o.customer#.

Step-by-step explanation:

A SQL statement is a set of instruction that consists of identifiers, parameters, variables, names, data types, and SQL reserved words that compiles successfully.

The SQL commands are mainly categorized into five categories:

  • DDL – Data Definition Language.
  • DQL – Data Query Language.
  • DML – Data Manipulation Language.
  • DCL – Data Control Language.
  • TCL – Transaction Control Language.

In this question, the correct answer is b). SELECT lastname, firstname, order# FROM customers LEFT OUTER JOIN orders o ON c.customer# = o.customer#.

This SQL statement uses a LEFT OUTER JOIN to combine the CUSTOMERS and ORDERS tables based on the customer# column.

It selects the lastname and firstname columns from the CUSTOMERS table and the order# column from the ORDERS table.

User Psmith
by
7.9k points