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 column1,column2,column3... FROM table_name;
Demo Database:
- Table Name : customers
customer_id | customer_no | customer_name | contact | country | |
---|---|---|---|---|---|
1 | CS0001 | Nielsen | 830180289158 | patric@erssmail.com | US |
2 | CS0002 | Tom | 301295114077 | tom@test.com | US |
3 | CS0003 | Sam | 443486006841 | sam@test.com | India |
4 | CS0004 | Jhon Smith | 797812460888 | jhon smith@test.com | US |
5 | CS0005 | Edwards | 369569573912 | edwards@test.com | Malaysia |
6 | CS0006 | Wilkinson | 902956510286 | wilkinson@test.com | Malaysia |
7 | CS0007 | Kevyn | 817079751978 | wilkinson@test.com | India |
8 | CS0008 | Dodson | 830180289156 | dodson@test.com | Malaysia |
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