To retrieve data from a MySQL database, you use the SELECT statement.
Syntax :
SELECT column1, column2, ... FROM table_name WHERE condition;
- column1, column2, ...: The columns you want to retrieve from the table. You can use * to select all columns.
- table_name: The name of the table from which you want to retrieve data.
- WHERE condition: An optional clause that allows you to specify conditions for filtering the rows.
Examples:
1.Select All Columns from a Table:
SELECT * FROM employees;
2. Select Specific Columns from a Table:
SELECT first_name, last_name, salary FROM employees;
3.Select with a Condition:
SELECT * FROM employees WHERE department_id = 1;
4.Select with Multiple Conditions:
SELECT * FROM employees WHERE department_id = 1 AND salary > 50000;
5.Select with Ordering:
SELECT * FROM employees ORDER BY last_name ASC;
6.Select with Limit:
SELECT * FROM employees LIMIT 10;