Podcast
Questions and Answers
What does the SQL condition 'WHERE column BETWEEN ... AND ...' achieve?
What does the SQL condition 'WHERE column BETWEEN ... AND ...' achieve?
- Selects records with column values within and including a specified interval. (correct)
- Selects records where the column value does not fall within the specified range.
- Selects all records where the column value equals the first value only.
- Selects all records where the column value is greater than the first value.
In SQL, how does the 'LIKE' operator operate?
In SQL, how does the 'LIKE' operator operate?
- It checks for a match with an exact string.
- It selects records where a value is null.
- It selects records that contain a specified range of values.
- It allows for partial matches based on a specified pattern. (correct)
Which of the following SQL queries correctly uses the 'IN' clause?
Which of the following SQL queries correctly uses the 'IN' clause?
- SELECT SALARY FROM EMPLOYEES WHERE SALARY IN BETWEEN 5000 AND 7000.
- SELECT ID FROM EMPLOYEES WHERE NAME IN ('Alice', 'Bob'). (correct)
- SELECT NAME FROM EMPLOYEES WHERE AGE = 30 OR 35 OR 40.
- SELECT VARDAS FROM EMPLOYEJAI WHERE SALARY IN ('500', '600').
What does the SQL clause 'WHERE column IS NULL' determine?
What does the SQL clause 'WHERE column IS NULL' determine?
If you want to combine multiple conditions in a SQL query, which operator can be used?
If you want to combine multiple conditions in a SQL query, which operator can be used?
In the statement 'SELECT * FROM EMPLOYEES WHERE SALARY > 300 AND STORE_ID = 2', what is required?
In the statement 'SELECT * FROM EMPLOYEES WHERE SALARY > 300 AND STORE_ID = 2', what is required?
What does the percentage symbol '%' represent in SQL 'LIKE' conditions?
What does the percentage symbol '%' represent in SQL 'LIKE' conditions?
How is 'NOT' used in SQL conditions?
How is 'NOT' used in SQL conditions?
Flashcards
WHERE clause
WHERE clause
Used to filter rows in a SQL query. It specifies conditions that rows must meet to be included in the result.
Comparison operators
Comparison operators
Symbols (=, >, <, >=, <=, !=) used to compare values in the WHERE clause (or any other condition).
BETWEEN
BETWEEN
Selects values within a given range (inclusive).
IN operator
IN operator
Signup and view all the flashcards
LIKE operator
LIKE operator
Signup and view all the flashcards
Wildcards (%)
Wildcards (%)
Signup and view all the flashcards
Wildcards (_)
Wildcards (_)
Signup and view all the flashcards
NULL values
NULL values
Signup and view all the flashcards
IS NULL
IS NULL
Signup and view all the flashcards
Logical operators (AND, OR, NOT)
Logical operators (AND, OR, NOT)
Signup and view all the flashcards
Equality operator ( = )
Equality operator ( = )
Signup and view all the flashcards
Study Notes
SQL WHERE Clause
- The WHERE clause filters records in a table
- It uses comparison operators like =, >, <, >=, <=, <> (not equal to)
- Example:
SELECT * FROM EMPLOYEES WHERE SALARY > 600
SQL WHERE BETWEEN ... AND
- The BETWEEN operator selects values within a range
- Includes the start and end values
- Example:
SELECT * FROM PRODUCTS WHERE PRICE BETWEEN 10 AND 20
SQL WHERE IN
- The IN operator selects rows where a column's value matches one of a list of values.
- Example:
SELECT * FROM CUSTOMERS WHERE CITY IN ('London', 'Paris', 'New York')
SQL WHERE LIKE
- The LIKE operator filters for values matching a pattern
- Uses wildcards:
%
(matches any sequence of characters),_
(matches any single character) - Example:
SELECT * FROM USERS WHERE NAME LIKE 'J%'
(finds names starting with 'J')
SQL WHERE NULL
- NULL represents missing or unknown values
- The IS NULL operator tests for NULL values
- Example:
SELECT * FROM ORDERS WHERE DELIVERY_DATE IS NULL
SQL WHERE (NOT, AND, OR)
- Combining multiple conditions with AND, OR, NOT
- AND requires all conditions to be true
- OR requires at least one condition to be true
- NOT reverses a condition
- Example:
SELECT * FROM ORDERS WHERE STATUS = 'Shipped' AND CUSTOMER_ID = 101
SQL WHERE (ORDER BY)
- Sorts query results
- Ascending order (by default):
- Example: SELECT * FROM PRODUCTS ORDER BY PRICE
- Descending order use DESC
- Example: SELECT * FROM PRODUCTS ORDER BY PRICE DESC
SQL (DISTINCT)
-
Selects only unique values for a column.
-
Example:
SELECT DISTINCT CITY FROM CUSTOMERS
SQL (LOWER/UPPER)
- LOWER transforms text to lowercase.
- UPPER transforms text to uppercase.
SQL (CONCAT)
- Joins strings together into a new string
- Example:
SELECT CONCAT(FirstName,' ',LastName) AS FullName
SQL (Aggregate Functions)
- Used with
GROUP BY
clause to perform calculations on values within that group - Examples:
- AVG(): Calculates the average
- COUNT(): Counts rows
- MAX(): Finds the maximum value
- MIN(): Finds the minimum value
- SUM(): Calculates the sum
SQL (HAVING)
- Filters groups after a
GROUP BY
operation. - Example: selects customers who have placed more than two orders
SELECT COUNT(*), CustomerID FROM Orders GROUP BY CustomerID HAVING COUNT(*) > 2
General SQL Syntax and Structure
SELECT
clause specifies which columns to retrieveFROM
clause specifies which table to retrieve data fromWHERE
clause filters the data based on conditionsGROUP BY
clause groups rows with the same values in specified columnsHAVING
clause filters groups based on conditionsORDER BY
clause sorts results
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.