Podcast
Questions and Answers
What is the purpose of the WHERE clause in SQL?
What is the purpose of the WHERE clause in SQL?
How can you get the total number of rows in a table?
How can you get the total number of rows in a table?
What is the purpose of the SELECT SUM(col) function?
What is the purpose of the SELECT SUM(col) function?
How do you get rows where a number is greater than or equal to a value?
How do you get rows where a number is greater than or equal to a value?
Signup and view all the answers
What is the purpose of the SELECT AVG(col) function?
What is the purpose of the SELECT AVG(col) function?
Signup and view all the answers
How do you get rows where a number is greater than a value?
How do you get rows where a number is greater than a value?
Signup and view all the answers
What is the purpose of the SELECT COUNT(*) function?
What is the purpose of the SELECT COUNT(*) function?
Signup and view all the answers
How can you get the mean value of a column?
How can you get the mean value of a column?
Signup and view all the answers
What is the purpose of the ORDER BY clause in a SELECT statement?
What is the purpose of the ORDER BY clause in a SELECT statement?
Signup and view all the answers
How do you get rows where values are missing in a specific column?
How do you get rows where values are missing in a specific column?
Signup and view all the answers
What is the purpose of the LIMIT clause in a SELECT statement?
What is the purpose of the LIMIT clause in a SELECT statement?
Signup and view all the answers
How do you get unique values in a column?
How do you get unique values in a column?
Signup and view all the answers
What is the purpose of the WHERE clause in a SELECT statement?
What is the purpose of the WHERE clause in a SELECT statement?
Signup and view all the answers
How do you get the current date and datetime?
How do you get the current date and datetime?
Signup and view all the answers
What is the purpose of the FROM clause in a SELECT statement?
What is the purpose of the FROM clause in a SELECT statement?
Signup and view all the answers
How do you get rows where values are not missing in a specific column?
How do you get rows where values are not missing in a specific column?
Signup and view all the answers
What is the purpose of the BINARY operator in a WHERE clause?
What is the purpose of the BINARY operator in a WHERE clause?
Signup and view all the answers
What is the purpose of the SHOW TABLES command?
What is the purpose of the SHOW TABLES command?
Signup and view all the answers
What is the purpose of the GROUP BY clause in SQL?
What is the purpose of the GROUP BY clause in SQL?
Signup and view all the answers
What is the syntax to get rows where a number is between two values in SQL?
What is the syntax to get rows where a number is between two values in SQL?
Signup and view all the answers
What is the purpose of the ORDER BY clause in SQL?
What is the purpose of the ORDER BY clause in SQL?
Signup and view all the answers
How do you get rows where text contains specific letters in SQL?
How do you get rows where text contains specific letters in SQL?
Signup and view all the answers
What is the purpose of the HAVING clause in SQL?
What is the purpose of the HAVING clause in SQL?
Signup and view all the answers
How do you select all columns from a table in SQL?
How do you select all columns from a table in SQL?
Signup and view all the answers
What is the purpose of the WHERE clause in SQL?
What is the purpose of the WHERE clause in SQL?
Signup and view all the answers
How do you get rows where one condition and another condition holds in SQL?
How do you get rows where one condition and another condition holds in SQL?
Signup and view all the answers
What is the purpose of the AS keyword in SQL?
What is the purpose of the AS keyword in SQL?
Signup and view all the answers
What is the syntax to get summaries grouped by values with a specific order in SQL?
What is the syntax to get summaries grouped by values with a specific order in SQL?
Signup and view all the answers
Study Notes
Filtering Data
- Use
WHERE
clause to filter data based on conditions - Filter on numeric columns:
-
WHERE col > n
to get rows where a number is greater than a value -
WHERE col >= n
to get rows where a number is greater than or equal to a value -
WHERE col BETWEEN m AND n
to get rows where a number is between two values (inclusive)
-
- Filter on text columns:
-
WHERE col = 'x'
to get rows where text is equal to a value -
WHERE col IN ('x', 'y')
to get rows where text is one of several values -
WHERE col LIKE '%abc%'
to get rows where text contains specific letters
-
- Filter on multiple columns:
-
WHERE condn1 AND condn2
to get rows where one condition and another condition holds
-
Aggregating Data
- Use
SELECT
clause to aggregate data - Simple aggregations:
-
SELECT COUNT(*)
to get the total number of rows -
SELECT SUM(col)
to get the total value of a column -
SELECT AVG(col)
to get the mean value of a column
-
- Get summaries grouped by values:
-
SELECT col, COUNT(*)
withGROUP BY col
to get summaries grouped by values -
SELECT col, SUM(x)
withGROUP BY col
to get summaries grouped by values with sum -
SELECT col, COUNT(*)
withGROUP BY col ORDER BY smmry DESC
to get summaries grouped by values in order of summaries
-
Querying Tables
- Get all columns from a table using
SELECT *
- Get a column from a table by name using
SELECT col
- Get multiple columns from a table by name using
SELECT col1, col2
- Override column names with
SELECT col AS new_name
- Arrange the rows in descending order of values in a column with
ORDER BY col DESC
- Limit the number of rows returned with
LIMIT n
MySQL-Specific Syntax
- Not all code works in every dialect of SQL
- Use
WHERE BINARY condn
to get case sensitive matching - Get the current date with
CURDATE()
and the current datetime withNOW()
orCURTIME()
- List available tables with
SHOW TABLES
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your skills on filtering data in MySQL, including filtering on numeric columns, and performing simple aggregations.