To retrieve data, use the following syntax:
SELECT column1, column2, ...
FROM table_name;
column1
, column2
, ...: The columns you want to retrieve. Use *
to select all columns.table_name
: The name of the table from which to fetch data.Let’s retrieve all the columns from the employees
table:
SELECT * FROM employees;
This query fetches all columns (*
) and all rows from the employees
table.
If you want to fetch only specific columns, list them instead of using *
:
SELECT name, email FROM employees;
This retrieves only the name
and email
columns from the employees
table.
You can also add conditions to filter data using the WHERE
clause:
SELECT * FROM employees WHERE name = 'Jane Doe';
This query will fetch all columns for employees where the name
is 'Jane Doe'
.
This query fetches all columns (*
) and all rows from the employees
table.
The SELECT
query is one of the most fundamental and frequently used operations in MySQL. It enables you to retrieve and display data based on specific needs, whether you're fetching all records or applying conditions for filtering. Mastering the SELECT
query is essential for working with databases efficiently.