MySQL - Select Query


The MySQL SELECT command is used to fetch records from the database. We can fetch records of all fields or specified fields.

Syntax
SELECT field1,field2,field3... FROM table_name;
Demo Database:
  • Table Name : customers
customer_id customer_no customer_name contact email
1 CS0001 Nielsen 724901642310 nielsen@test.com
2 CS0002 Tom 301295114077 tom@test.com
3 CS0003 Sam 443486006841 sam@test.com
4 CS0004 Jhon Smith 797812460888 jhon smith@test.com
5 CS0005 Edwards 369569573912 edwards@test.com
6 CS0006 Wilkinson 902956510286 wilkinson@test.com
7 CS0007 Kevyn 817079751978 wilkinson@test.com
8 CS0008 Dodson 830180289156 dodson@test.com
SELECT * (all columns)

By using * operator, we can select all columns from the table. The following Query selects all columns from the 'customers' table.

Example
SELECT * FROM customers;
Try it Yourself
SELECT - Single Column

The following Query selects 'customer_name' from the 'customers' table.

Example
SELECT customer_name FROM customers;
Try it Yourself
SELECT - Multiple Columns

The following Query selects 'customer_no','customer_name' and 'contact' columns from the 'customers' table.

Example
SELECT customer_no,customer_name,contact FROM customers;
Try it Yourself