Challenge your grasp of fundamental SQL concepts, syntax, and commands tailored for data engineering tasks in both BigQuery and MySQL environments. This quiz covers SQL basics, common operators, filtering, sorting, and essential best practices for efficient database management and querying.
Which SQL command retrieves all columns and rows from the table named 'employees'?
Explanation: The correct syntax to retrieve all columns and rows from a table in SQL is 'SELECT * FROM table_name;'. The asterisk (*) means all columns. The distractors use incorrect SQL keywords: 'FETCH ALL' and 'GET ... ALL' are not standard SQL, and 'DISPLAY * employees;' is not a recognized SQL command.
What is the correct SQL command to insert values 5 and 'John' into columns 'id' and 'name' of the 'users' table?
Explanation: To insert data in SQL, you use 'INSERT INTO' followed by the table name, column list, and 'VALUES' with the actual data. Other options use incorrect SQL syntax or keywords: 'ADD INTO', 'INSERT users VALUES id=5, name='John';', and 'NEW ROW' are not valid.
How do you update the 'salary' field to 60000 in all records where 'position' is 'analyst' in an 'employees' table?
Explanation: The proper SQL statement starts with 'UPDATE', then the table name, and uses 'SET' to specify the new value, followed by 'WHERE' to filter. The distractors contain nonstandard SQL keywords like 'CHANGE', 'MODIFY', or incorrect use of 'IF' and 'WHEN' instead of 'WHERE'.
Which SQL statement removes all entries from the 'temp_data' table where the 'flag' column is set to 0?
Explanation: 'DELETE FROM ... WHERE ...' is the correct syntax for removing rows by condition. 'REMOVE FROM' is invalid, 'DELETE temp_data WHERE...' misses the 'FROM' keyword, and 'DROP' is used to delete entire tables, not individual rows.
How can you select all records from the 'students' table where the 'age' is greater than 18?
Explanation: Filters in SQL are applied with the 'WHERE' clause in a SELECT statement. 'WITH', 'HAVING', and putting '>18' after SELECT are inappropriate for this context. 'HAVING' is used with group functions, not simple filtering.
What SQL clause will order the results of a query by the 'created_at' column in descending order?
Explanation: 'ORDER BY column DESC' is the standard way to sort in descending order. 'SORT BY', 'ORDER ... descending', and 'DOWNWARD' are not recognized SQL keywords. Only 'DESC' is valid.
Which SQL statement retrieves only the 'email' and 'signup_date' columns from the 'accounts' table?
Explanation: To retrieve specific columns, list them after SELECT and before FROM. The other options use incorrect commands such as 'PICK', 'ONLY', or wrong bracket usage.
Which SQL keyword calculates the total number of rows in the 'orders' table?
Explanation: 'COUNT(*)' returns the number of rows in a table. 'SUM(*)' is not valid and is used to total numbers, not row counts. 'TOTAL' and 'QUANTITY' are not standard SQL aggregate functions.
In SQL, which symbol is used as a wildcard to match any sequence of characters in a 'LIKE' condition?
Explanation: The percent sign (%) in 'LIKE' is used to represent zero or more characters. Other symbols such as '#', '&', and '$' have no wildcard role in standard SQL 'LIKE' patterns.
What is the correct way to limit the output to 10 rows in a MySQL SELECT query?
Explanation: In MySQL, the 'LIMIT' clause restricts the number of rows returned. 'TOP' is used in some other SQL variants, 'TAKE' and 'FETCH 10 ROWS' are not valid in MySQL syntax.
How can you display the 'user_id' column as 'ID' in query results from the 'users' table?
Explanation: The 'AS' keyword renames a column in SQL query results. The other options use nonstandard SQL keywords like 'RENAME', 'TO', or assignment symbols, which are incorrect.
Which SQL clause will select products where 'price' is above 50 and 'category' is 'books'?
Explanation: Combining conditions in SQL is done with 'AND' for both to be true. Using a comma or 'BETWEEN' is incorrect, and 'OR' would select records where either condition is true, not necessarily both.
How can you select all events from the 'events' table that occurred on '2024-06-01'?
Explanation: A filter by exact date uses 'WHERE column = value'. The 'WHEN', 'ON', and 'DATE' clauses here do not perform filtering in SQL. Only 'WHERE' is correct.
Which SQL expression finds all rows in the 'orders' table where the 'shipped_date' is unspecified?
Explanation: To check for null values, you must use 'IS NULL' in SQL. The '==' operator, 'BLANK', or the string 'NULL' are not recognized for this purpose.
Which SQL command sorts the 'products' table by 'product_name' in alphabetical order?
Explanation: 'ORDER BY column ASC' arranges results in ascending (A-Z) order. The distractors use 'SORT' and 'ORDER ... ALPHABET', which are not SQL syntax, or confuse 'GROUP BY' with sorting.