SQL Select Grouping information - The DISTINCT keyword

The text below explains the correct answers to the quiz.
 
1. Given the following columns from a table named MyTable:
MyLastName MyFirstName MyAddress MyCity MyState MyZipCode
If you want to sort the results based on MyLastName, what statement would you use if you wanted to see all rows (including duplicates) in the results?
  A.
SELECT * FROM MyTable 
GROUP BY MyLastName
  B.
						 
SELECT * FROM MyTable 
SORTED BY MyLastName
  C.
SELECT * FROM MyTable 
ORDER BY MyLastName
  D.
SELECT * FROM MyTable 
GROUP BY MyLastName, DUPLICATES="Y"
  The correct answer is C.
Using the GROUP BY clause would eliminate duplicates. SORTED BY, which is on choice B, is not the correct syntax for SQL.
2. Using the table from Question 1, which statement below could you use to select only the unique states that are in the table?
  A. SELECT MyState FROM MyTable GROUP BY MyState
  B. SELECT * FROM MyTable SORTED BY MyState
  C. SELECT * FROM MyTable ORDER BY MyState
  D. SELECT * FROM MyTable GROUP BY MyState, DUPLICATES="Y"
  The correct answer is A.
The GROUP BY clause would select and sort all the states in the table. It would also eliminate the duplicates from the results.

3. What's wrong with the following statement?
SELECT * FROM MyTable GROUP BY MyState
  A. Nothing is wrong with this statement
  B. An ORDER BY clause should be used
  C. You must indicate all the columns from the table in the GROUP BY clause
  D. The "*" operator cannot be used in GROUP BY statements
  The correct answer is C.
When you use "*" in the SELECT statement, you will need to indicate all the table columns that the engine will use in the grouping. The alternative to this is to include specific column names in both the SELECT statement and the GROUP BY clause.

4. If you have a table containing sales information for an organization and want to query that table to retrieve sales value totals for each district, but not the detail line items, what type of statement 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
  The correct answer is B.
The GROUP BY statement is best suited to this task because it will eliminate duplicates but still allow you to summarize results by district as needed.

5. If you want to show the grades from a Grades table only for those students with a specific grade level, maintained in a StudentInfo table, what type of statement would you use?
  A. A sub-SELECT statement to pull the related information between the two tables
  B. A GROUP BY to relate the tables and summarize the grades
  C. A SELECT statement with the DISTINCT keyword to summarize grade information
  D. An ORDER BY clause to relate the results
  The correct answer is A.
The sub-SELECT statement will let you first query the StudentInfo table, then use that information to pull appropriate Grades table information.

6. If you want to query a sales table to find out which customers have ordered, and only want a listing of customers represented in the table and no details about the orders or any information about duplicates, which statement or clause is most appropriate?
  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
  The correct answer is C.
The DISTINCT clause will filter the results for you, providing the unique information to fulfill the query and give the customer information you need.

7. Which of the following is not true when using an EQUALS clause?
  A. The sub-SELECT statement needs to return only one result
  B. You cannot use a WHERE clause with the subSELECT statement if you use the EQUALS clause
  C. The EQUALS clause can be used for both SELECT and subSELECT statements
  D. You use the "=" symbol rather than the word "EQUALS" when running the query
  The correct answer is B.
You can use a WHERE clause even if you also use an EQUALS clause.