Select Statement  «Prev 

SQL Select - Quiz

Each question is worth one point. Select the best answer or answers for each question.
1. Given the following columns from a table named MyTable:
MyLastName MyFirstName MyAddress MyCity MyState MyZipCode
Which SQL statement sorts all rows from MyTable by MyLastName using the default ascending order syntax?
Please select the best answer.
  A. SELECT * FROM MyTable GROUP BY MyLastName
  B. SELECT * FROM MyTable ORDER BY MyLastName ASC
  C. SELECT * FROM MyTable ORDER BY MyLastName
  D. SELECT DISTINCT * FROM MyTable ORDER BY MyLastName

2. Which SQL statement selects only the unique states from MyTable?
Please select the best answer.
  A. SELECT DISTINCT MyState FROM MyTable
  B. SELECT MyState FROM MyTable ORDER BY MyState
  C. SELECT MyState FROM MyTable GROUP BY MyState
  D. SELECT * FROM MyTable WHERE MyState IS NOT NULL

3. Why is the statement SELECT * FROM MyTable GROUP BY MyState invalid?
Please select the best answer.
  A. All non-aggregated columns in the SELECT clause must appear in the GROUP BY clause.
  B. The SELECT * syntax is not allowed in any SQL statement.
  C. A WHERE clause is required when using GROUP BY.
  D. The GROUP BY clause cannot reference the MyState column.

4. To query a sales table and retrieve the total sales value for each district, excluding detail line items, which SQL clause would you use?
Please select the best answer.
  A. A subquery to limit the results by district
  B. A GROUP BY clause to summarize the results
  C. A SELECT statement with the DISTINCT keyword to filter detail lines
  D. An ORDER BY clause to group and summarize results

5. To display grades from a Grades table for students with a specific grade level from a StudentInfo table, which SQL clause or statement would you use?
Please select the best answer.
  A. A JOIN clause to combine the two tables
  B. A subquery to filter grades based on StudentInfo
  C. A GROUP BY clause to summarize grades
  D. An ORDER BY clause to sort the results

6. Which SQL clause retrieves a list of unique customers from a sales table, excluding order details and duplicates?
Please select the best answer.
  A. A subquery to select the unique rows for the query
  B. A GROUP BY clause to summarize customer order information and then retrieve the order information
  C. A SELECT statement with the DISTINCT keyword to remove duplicate customer values
  D. An ORDER BY clause to sort and filter the results

7. Which statement about the = operator in SQL is not true?
Please select the best answer.
  A. It compares two non-null values for equality in a WHERE clause.
  B. It can be used with a scalar subquery that returns one value.
  C. It can be used instead of IS NULL to find null values.
  D. It can compare a column value to a literal value.