[SQL] According to standard operator precedence in SQL, which of the following operators is evaluated before AND but after comparison operators like = or >?
The NOT operator.
WHY: Standard SQL evaluation order requires the database to process Mathematical Operators first, then Comparison Operators, then logical NOT, then logical AND, then logical OR.
[SQL] Reinforcement: Fill in the evaluation order for logical operators in SQL: AND, OR, NOT.
[SQL] Mastery: Why is it a best practice to use parentheses in complex SQL WHERE clauses even if you know the exact operator precedence?
Parentheses guarantee the intended logic is executed and make the SQL code much easier for other developers to read and maintain, rather than forcing them to rely on memorized precedence rules.
[SQL] Which comparison operators are used to check for inequality in SQL?
The standard SQL operator for inequality is <> (less than and greater than symbols together). Many systems also accept != (exclamation point and equals sign).
WHY: <> means literally less than OR greater than, which equates to not equal.
[SQL] Reinforcement: Write a SQL WHERE clause to filter out any products from a Products table where the Category is “Discontinued”.
WHERE Category <> “Discontinued”
NOTE: Using != is also acceptable in most modern relational database management systems.
[SQL] Mastery: Between the <> operator and the != operator for inequality in SQL, which one is considered the ISO standard?
The <> operator is the official ISO standard for SQL. The != operator is a common vendor extension adopted from C-style programming languages.
[SQL] A Departments table contains many employees in each department. If you run SELECT DepartmentName FROM Employees;, you will get many duplicate values. Which keyword should be added to the SELECT clause to return only the unique department names?
The DISTINCT keyword.
WHY: SELECT DISTINCT filters the result set to remove duplicate rows, returning only unique values for the specified columns.
[SQL] Reinforcement: Provide the exact SQL syntax to retrieve only unique job titles from an Employees table.
SELECT DISTINCT JobTitle FROM Employees;
MNEMONIC: DISTINCT means different or unique.
[SQL] Mastery: What happens if you use the DISTINCT keyword on multiple columns, such as SELECT DISTINCT City, State FROM Customers?
SQL evaluates the COMBINATION of the columns. It will return unique pairs of City and State, meaning the same state can appear multiple times as long as the city is different in that row.
[SQL] What is the fundamental difference between the CURTIME() and TIME() functions in SQL?
CURTIME() returns the current time of the system clock. TIME(expression) extracts the time portion from a given datetime string or variable.
WHY: CURTIME generates new data based on right now. TIME parses existing data.
[SQL] Reinforcement: Fill in the blank to extract just the time portion from an order timestamp: SELECT _______(OrderDate) FROM Orders;
TIME
The complete syntax is: SELECT TIME(OrderDate) FROM Orders;
[SQL] Mastery: If a SQL database stores a timestamp as “2026-02-26 14:30:00”, what exactly will the TIME() function return?
The TIME() function will return “14:30:00”. It drops the year, month, and day.
[SQL] A query needs to extract the first 4 characters from a ProductCode string. Which SQL function should be used?
The LEFT() function.
WHY: LEFT(ProductCode, 4) starts at the leftmost character of the string and extracts the specified number of characters.
[SQL] Reinforcement: Write the exact SQL SELECT clause to pull the first 3 letters of a column named PhoneNumber.
SELECT LEFT(PhoneNumber, 3)
MNEMONIC: LEFT reads from the start of the word.
[SQL] Mastery: What SQL function would you use to extract characters from the middle of a string instead of the left or right?
The SUBSTRING() function.
EXAMPLE: SUBSTRING(ProductCode, 3, 4) starts at the third character and pulls the next four characters.
[SQL] A developer wants to return a list of unique combinations of City and State from a Customers table. Which SQL syntax is correct?
SELECT DISTINCT City, State FROM Customers;
WHY: Placing DISTINCT immediately after SELECT applies the uniqueness constraint to the entire row of results returned.
[SQL] Reinforcement: Debug this SQL query that is failing to return unique pairs of regions: SELECT City, DISTINCT State FROM Locations;
The DISTINCT keyword must come immediately after SELECT, before any column names.
CORRECT: SELECT DISTINCT City, State FROM Locations;
[SQL] Mastery: Does using SELECT DISTINCT in SQL slow down query performance?
Yes, DISTINCT often forces the database engine to sort the data or use a hash table behind the scenes to identify and remove duplicates, which requires extra processing time.
[SQL] A query is written as SELECT * FROM Employees, Departments; without a WHERE or ON clause. What type of result will this produce?
A Cartesian Product, also known as a CROSS JOIN.
WHY: Without a join condition, every single row in the Employees table is blindly joined to every single row in the Departments table.
[SQL] Reinforcement: Define a Cartesian Product in plain English.
A Cartesian Product occurs when a database multiplies every row from one table against every row from another table because no linking relationship was defined.
MNEMONIC: CROSS JOIN equals CROSS MULTIPLY.
[SQL] Mastery: If an Employees table has 10 rows and a Departments table has 5 rows, how many rows will be returned by a query with no JOIN condition?
50 rows.
WHY: 10 employee rows multiplied by 5 department rows equals 50 total combinations.
[SQL] An analyst needs to create a list of each DepartmentName and the number of employees in that department. Which SQL query correctly provides this information?
SELECT DepartmentName, COUNT() FROM Employees GROUP BY DepartmentName;
WHY: You must use GROUP BY with the non-aggregated column (DepartmentName) so the COUNT function knows exactly how to group the totals.
[SQL] Reinforcement: Fill in the blank to count products per category: SELECT Category, COUNT() FROM Products ________ Category;
GROUP BY
The full clause is GROUP BY Category;
[SQL] Mastery: What SQL error occurs if you include a column in the SELECT clause alongside an aggregate function like COUNT(), but forget to include that column in the GROUP BY clause?
The database will return a syntax error stating that the column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.