Selected topic
Data Query Language Dql
Prefer practical output? Use related tools below while reading.
==========================
The SELECT statement is used to retrieve data from a database table. It's one of the most basic and frequently used queries in SQL.
sql
SELECT column1, column2, ...
FROM tablename;column1, column2, ...: Specify the columns you want to retrieve.FROM tablename;: Specify the table from which to retrieve data.employees with the following structure:| id | name | age | department |
|----|--------|-----|------------|
| 1 | John | 25 | Sales |
| 2 | Jane | 30 | Marketing |
| 3 | Joe | 28 | IT |
To retrieve the name and age of all employees in the Sales department, we can use the following query:
sql
SELECT name, age
FROM employees
WHERE department = 'Sales';
In this example, we used a filter clause (WHERE) to narrow down the results to only those rows where department is 'Sales'.
) instead of listing specific columns: SELECT * FROM employees;ORDER BY clause: SELECT name, age FROM employees ORDER BY age ASC; (ascends by age)LIMIT clause: SELECT name, age FROM employees LIMIT 2;SELECT statement. There are many more advanced features and options available in SQL.