Navigate
JavaScript Tutorial for Beginners
The Ultimate CSS Tutorial for Beginners
Data Structure Tutorial for Beginners
ReactJS Tutorial for Beginners
Java Tutorial for Beginners
Node.js Tutorial for Beginners
SQL Tutorial for Beginners
Basic SQL Queries
Content
- Basic SQL Queries
- Retrieving Data
- Filtering Data
- Sorting Data
- Combining Conditions
- Updated on 10/09/2024
- 450 Views
Retrieving Data
Use the SELECT statement to fetch data from a database. Example: SELECT * FROM employees;
Filtering Data
Use the WHERE clause to filter records. Example: SELECT * FROM employees WHERE age > 25;
Sorting Data
Use the ORDER BY clause to sort data in ascending or descending order. Example: SELECT * FROM employees ORDER BY age ASC;
Combining Conditions
Use AND and OR to combine multiple conditions. Example: SELECT * FROM employees WHERE age > 25 AND salary > 40000;
Activity
Write a query to find all employees who are older than 25 and have a salary greater than $40,000. Sort the results by age in ascending order.
Quiz
1. How do you filter records in SQL?
- a) FILTER BY
- b) WHERE
- c) ORDER BY
- d) SELECT
2. Which clause is used to sort query results?
- a) SORT BY
- b) ORDER BY
- c) GROUP BY
- d) FILTER BY
3. What will the following query return? SELECT * FROM employees WHERE department = 'Sales';
- a) All employees
- b) Employees in the Sales department
- c) Employees not in the Sales department
- d) Employees with no department
4. How can you sort results in descending order?
- a) ORDER BY column DESC
- b) SORT column DESC
- c) GROUP BY column DESC
- d) FILTER BY column DESC
5. What does the AND operator do in SQL queries?
- a) Combines conditions to include records that meet all conditions
- b) Excludes records that meet certain conditions
- c) Joins multiple tables
- d) Sorts data