What does the SELECT statement do?
Retrieves data from a database.
What does the WHERE clause do?
Filters records based on a condition.
What does ORDER BY do?
Sorts the results.
What does COUNT(*) return?
The total number of rows.
What is a database?
A collection of organized data.
Write a query to select all columns from a table called Students.
SELECT * FROM Students;
Select all students who are 13 years old.
SELECT * FROM Students
WHERE Age = 13;
Sort students by age from smallest to largest.
Count how many students are in the table.
SELECT COUNT(*) FROM Students;
What is a table?
A collection of rows and columns that stores data.
Select only the FirstName column from the Students table.
SELECT FirstName FROM Students;
Select students whose name is "Maria".
SELECT * FROM Students
WHERE FirstName = 'Maria';
Sort students by age from largest to smallest.
SELECT * FROM Students
ORDER BY Age DESC;
Count how many students are 13 years old.
What is a column?
A field that stores one type of data.
Select the FirstName and Age columns from the Students table.
SELECT FirstName, Age FROM Students;
Select students older than 12.
SELECT * FROM Students
WHERE Age > 12;
Sort students alphabetically by last name.
SELECT * FROM Students
ORDER BY LastName ASC;
Count how many students are in each age group.
What is a row?
A single record in a table.
Select all students but rename the FirstName column as Name.
SELECT FirstName AS Name FROM Students;
Select students who are 12 or 13 years old.
SELECT * FROM Students
WHERE Age = 12 OR Age = 13;
Sort students by age (oldest first), and if two students are the same age, sort them by first name.
SELECT * FROM Students
ORDER BY Age DESC, FirstName ASC;
Count how many students are in each age group and sort by age.
What does the asterisk * mean in SQL?
It selects all columns.