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, including duplicates?
  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?
  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?
  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?
  A. A sub-SELECT to limit the results by district
  B. A GROUP BY 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?
  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?
  A. A sub-SELECT to select the unique rows for the query
  B. A GROUP BY to summarize the customer order information, then pull the order information
  C. A SELECT statement with the DISTINCT keyword to filter the table's duplicate results
  D. An ORDER BY clause to sort and filter the results

7. Which statement about the `=` operator in SQL is not true?
  A. It compares two values for equality in a WHERE clause.
  B. It can be used in both simple and subquery comparisons.
  C. It requires a subquery to return exactly one row in a comparison.
  D. It cannot be used with NULL values to check for equality.



Your Score: 0