SQL SELECT * FROM
SELECT statement to fetch data from a table of a MySQL database.
Syntax of the SELECT statement
SELECT column_names FROM table_name;
- table_name – Name of the table whose data you want to get.
- column_names – Specify the column names (
column3, …) that will be listed in the fetched data. Add * instead of the column names if you want to fetch all the columns.
Example of SELECT statement
- Database Name –
- Table Name –
userstable columns –
data of the `users` table
1. Get all data with all columns
The following both SQL statements will do the same job. Get all the data from the
SELECT name, age, email FROM users;
SELECT * FROM users;
2. Get all data with specific columns
The following SQL statement will skip the email column. Don’t specify the column name If you don’t want the data of that column.
SELECT name, age FROM users;
3. SELECT * FROM with WHERE clause
If you want to fetch only those rows that fulfill your condition, you can do this with the help of the WHERE clause.
In the following image of a SQL table, there is a list of users. Now, you want to get only those users whose age is below 18. Let’s see how you can implement this –
In the following SQL code, the
< is a comparison operator.
age < 18 means select those users whose age is less than 18.
SELECT * FROM users WHERE age < 18;