Podcast
Questions and Answers
What is the purpose of the WHERE clause in SQL?
What is the purpose of the WHERE clause in SQL?
- To aggregate data to calculate a total or average
- To filter data based on a condition (correct)
- To sort data in ascending or descending order
- To group data based on a particular column
How can you get the total number of rows in a table?
How can you get the total number of rows in a table?
- Using the SELECT AVG(*) function
- Using the SELECT GROUP(*) function
- Using the SELECT COUNT(*) function (correct)
- Using the SELECT SUM(*) function
What is the purpose of the SELECT SUM(col) function?
What is the purpose of the SELECT SUM(col) function?
- To get the maximum value of a column
- To get the minimum value of a column
- To get the total value of a column (correct)
- To get the average value of a column
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?
What is the purpose of the SELECT AVG(col) function?
What is the purpose of the SELECT AVG(col) function?
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?
What is the purpose of the SELECT COUNT(*) function?
What is the purpose of the SELECT COUNT(*) function?
How can you get the mean value of a column?
How can you get the mean value of a column?
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?
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?
What is the purpose of the LIMIT clause in a SELECT statement?
What is the purpose of the LIMIT clause in a SELECT statement?
How do you get unique values in a column?
How do you get unique values in a column?
What is the purpose of the WHERE clause in a SELECT statement?
What is the purpose of the WHERE clause in a SELECT statement?
How do you get the current date and datetime?
How do you get the current date and datetime?
What is the purpose of the FROM clause in a SELECT statement?
What is the purpose of the FROM clause in a SELECT statement?
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?
What is the purpose of the BINARY operator in a WHERE clause?
What is the purpose of the BINARY operator in a WHERE clause?
What is the purpose of the SHOW TABLES command?
What is the purpose of the SHOW TABLES command?
What is the purpose of the GROUP BY clause in SQL?
What is the purpose of the GROUP BY clause in SQL?
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?
What is the purpose of the ORDER BY clause in SQL?
What is the purpose of the ORDER BY clause in SQL?
How do you get rows where text contains specific letters in SQL?
How do you get rows where text contains specific letters in SQL?
What is the purpose of the HAVING clause in SQL?
What is the purpose of the HAVING clause in SQL?
How do you select all columns from a table in SQL?
How do you select all columns from a table in SQL?
What is the purpose of the WHERE clause in SQL?
What is the purpose of the WHERE clause in SQL?
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?
What is the purpose of the AS keyword in SQL?
What is the purpose of the AS keyword in SQL?
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?
Flashcards are hidden until you start studying
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 valueWHERE col >= n
to get rows where a number is greater than or equal to a valueWHERE 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 valueWHERE col IN ('x', 'y')
to get rows where text is one of several valuesWHERE 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 rowsSELECT SUM(col)
to get the total value of a columnSELECT 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 valuesSELECT col, SUM(x)
withGROUP BY col
to get summaries grouped by values with sumSELECT 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.