Podcast
Questions and Answers
Which SQL clause is used with the LIKE
operator to specify a search pattern?
Which SQL clause is used with the LIKE
operator to specify a search pattern?
- ORDER BY
- GROUP BY
- WHERE (correct)
- HAVING
Which wildcard character in SQL LIKE
is used to represent zero or more characters?
Which wildcard character in SQL LIKE
is used to represent zero or more characters?
- []
- #
- % (correct)
- _
Which SQL LIKE
pattern would you use to find all names that start with 'A'?
Which SQL LIKE
pattern would you use to find all names that start with 'A'?
- '_A'
- '%A'
- 'A%' (correct)
- '[^A]%'
- '[A]%'
Which SQL LIKE
pattern would you use to find all cities containing 'es'?
Which SQL LIKE
pattern would you use to find all cities containing 'es'?
To find cities that have six letters with the second letter being 'o', and ending in 'ondon', what LIKE
pattern would you use?
To find cities that have six letters with the second letter being 'o', and ending in 'ondon', what LIKE
pattern would you use?
If you want to find all last names ending with 'son', how would you structure your SQL LIKE
clause?
If you want to find all last names ending with 'son', how would you structure your SQL LIKE
clause?
What is the main purpose of the SQL IN
operator?
What is the main purpose of the SQL IN
operator?
Which SQL statement correctly filters employees in the 'HR', 'IT', or 'Sales' departments using the IN
operator?
Which SQL statement correctly filters employees in the 'HR', 'IT', or 'Sales' departments using the IN
operator?
How can the SQL IN
operator be used with subqueries?
How can the SQL IN
operator be used with subqueries?
What is the purpose of the SQL BETWEEN
operator?
What is the purpose of the SQL BETWEEN
operator?
To find orders placed in 2024, which SQL statement using the BETWEEN
operator would you use?
To find orders placed in 2024, which SQL statement using the BETWEEN
operator would you use?
How would you select products with prices between 100 and 500 (inclusive) using the SQL BETWEEN
operator?
How would you select products with prices between 100 and 500 (inclusive) using the SQL BETWEEN
operator?
If you're searching customer_feedback
table for feedback where customer name contains 'a', what SQL query would you use?
If you're searching customer_feedback
table for feedback where customer name contains 'a', what SQL query would you use?
To find all feedback comments that begin with the word 'Good', which SQL query would you use?
To find all feedback comments that begin with the word 'Good', which SQL query would you use?
Which SQL query would you use to find feedback where the comment ends with the word 'service'?
Which SQL query would you use to find feedback where the comment ends with the word 'service'?
How do you select customer feedback with ratings of 3, 4, or 5?
How do you select customer feedback with ratings of 3, 4, or 5?
Given a table customer_feedback
, what SQL query would retrieve feedback provided specifically on '2024-03-01', '2024-03-05', and '2024-03-10'?
Given a table customer_feedback
, what SQL query would retrieve feedback provided specifically on '2024-03-01', '2024-03-05', and '2024-03-10'?
Which of the following is NOT a valid use case for the BETWEEN
operator?
Which of the following is NOT a valid use case for the BETWEEN
operator?
You want to retrieve records of all orders placed in the first half of 2024. Which BETWEEN
clause would achieve this?
You want to retrieve records of all orders placed in the first half of 2024. Which BETWEEN
clause would achieve this?
Given a table products
with a price
column, what SQL statement would retrieve items with prices of exactly 25, 50, or 75, using the most efficient approach?
Given a table products
with a price
column, what SQL statement would retrieve items with prices of exactly 25, 50, or 75, using the most efficient approach?
Flashcards
SQL LIKE operator
SQL LIKE operator
Used in a WHERE clause to search for a specified pattern in a column.
SQL Wildcard: %
SQL Wildcard: %
Matches zero or more characters.
SQL Wildcard: _
SQL Wildcard: _
Matches exactly one character.
SQL Wildcard: []
SQL Wildcard: []
Signup and view all the flashcards
SQL Wildcard: [^]
SQL Wildcard: [^]
Signup and view all the flashcards
SQL IN operator
SQL IN operator
Signup and view all the flashcards
SQL BETWEEN operator
SQL BETWEEN operator
Signup and view all the flashcards
Study Notes
SQL LIKE Operator
- Implemented in a WHERE clause to find a specific pattern in a column
- Syntax includes
SELECT column1, column2,... FROM table_name WHERE columnN LIKE pattern;
Wildcards Used with LIKE
%
matches zero or more characters, such as'M%'
matching "Mark" or "Maria"_
matches exactly one character, such as'M_'
matching "Ma" or "Mo"[ ]
matches any single character inside brackets;'[AB]%'
matches names beginning with A or B[^ ]
matches any character NOT in brackets;'[^M]%'
matches names not beginning with M
LIKE Pattern Examples
'a%'
finds entries starting with “a”'%a'
finds entries ending with "a"'%or%'
finds entries containing "or" anywhere'_r%'
finds entries where the second character is "r"'a_%'
finds entries starting with "a" and has at least 2 characters'a%o'
finds entries that start with "a" and end with "o"
LIKE Query Descriptions
SELECT * FROM Customers WHERE City LIKE 'ber%';
finds cities beginning with "ber" such as "Berlin"SELECT * FROM Customers WHERE City LIKE '%es%';
finds cities containing "es" such as "Brest" or "Estonia"SELECT * FROM Customers WHERE City LIKE '_ondon';
finds 6-letter cities with the second letter "o" and ending in "ondon" such as "London"SELECT * FROM Customers WHERE City LIKE 'L_n_on';
finds cities such as "London" or "Lennon" using the pattern L + any character + n + any character + on
Practice Modifications (LIKE)
SELECT * FROM employees WHERE last_name LIKE '%son';
retrieves names ending in "son"SELECT * FROM customers WHERE email LIKE '%gmail.com';
searches for emails with "gmail"
SQL IN Operator
- Filters records matching any value in a list
- Acts as shorthand for multiple OR conditions
- Syntax includes
SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2,...);
SELECT * FROM employees WHERE department IN ('HR', 'IT', 'Sales');
to filter employees in specific departments- The above is equivalent to
SELECT * FROM employees WHERE department = 'HR' OR department = 'IT' OR department = 'Sales';
SELECT * FROM students WHERE grade IN ('A', 'B', 'C');
locates students with grades A, B, or CSELECT * FROM orders WHERE customer_id IN (101, 102, 105);
locates orders by customers 101, 102, and 105SELECT * FROM products WHERE price IN (100, 200, 500);
locates products costing 100, 200, or 500
IN with Subqueries
SELECT * FROM employees WHERE department_id IN (SELECT id FROM departments WHERE location = 'New York');
SQL BETWEEN Operator
- Filters values within a defined range
- Works with numbers, dates, or text (alphabetically)
SELECT * FROM orders WHERE order_date BETWEEN '2024-01-01' AND '2024-12-31';
finds orders placed in 2024SELECT * FROM products WHERE price BETWEEN 100 AND 500;
finds products with prices between 100 and 500
Hands-On SQL Activity: Feedback Table
- Create a customer feedback table with the following statement
CREATE TABLE customer_feedback ( id INT PRIMARY KEY AUTO_INCREMENT, customer_name VARCHAR(50), feedback TEXT, rating INT, date_given DATE );
- Insert at least 5 entries of sample data
- Perform queries to retrieve certain data
Example Queries
SELECT * FROM customer_feedback WHERE customer_name LIKE '%a%';
finds feedback where the name contains "a"SELECT * FROM customer_feedback WHERE feedback LIKE 'Good%';
finds feedback where the comment starts with "Good"SELECT * FROM customer_feedback WHERE feedback LIKE '%service';
finds feedback where the comment ends with "service"SELECT * FROM customer_feedback WHERE rating IN (3, 4, 5);
finds feedback with a rating of 3, 4, or 5SELECT * FROM customer_feedback WHERE customer_name IN ('John', 'Emma','Michael');
finds feedback from "John", "Emma", or "Michael"SELECT * FROM customer_feedback WHERE date_given IN ('2024-03-01', '2024-03-05', '2024-03-10');
finds feedback given on specific dates
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.