W3. SQL Select Distinct Flashcards
Q: What does the SQL SELECT DISTINCT statement do?
A: It returns only distinct (unique) values from a specified column.
Q: Write an SQL query to select all distinct countries from the “Customers” table.
A: SELECT DISTINCT Country FROM Customers;
Q: Why might you use the SELECT DISTINCT statement?
A: To list only the different (unique) values in a column that may contain duplicates.
Q: What is the general syntax for the SELECT DISTINCT statement?
A: SELECT DISTINCT column1, column2, … FROM table_name;
Q: What happens if you omit DISTINCT in a SELECT statement?
A: The query will return all values, including duplicates, from the specified column(s).
Q: How can you count the number of distinct values in a column?
A: Use COUNT(DISTINCT column_name) in your query, e.g., SELECT COUNT(DISTINCT Country) FROM Customers;
Q: Is COUNT(DISTINCT column_name) supported in Microsoft Access?
A: No, Microsoft Access does not support COUNT(DISTINCT column_name) directly.
Q: How can you work around the lack of COUNT(DISTINCT column_name) support in MS Access?
A: Use a subquery: SELECT Count(*) AS DistinctCountries FROM (SELECT DISTINCT Country FROM Customers);