Loading

SQL SELECT statement

  • The SELECT statement is used to retrieve data from one or more tables in a database.

Syntax:

SELECT column1, column2,…
FROM table_name;
  • column1,column2,… : The columns you want to retrieve from the table.
  • table_name: The name of the table from which you want to retrieve data.
  • WHERE condition: An optional clause that specifies a condition that must be satisfied for the rows to be selected.

To select all the fields available in the table, we use this:

Syntax:

SELECT * FROM table_name;    
  • asterisks represent all attributes of the table.

Examples:

Customer table:

Customer IDCustomer NameCustomer NameCountry
1ShubhamThakurIndia
2PrashantChopraAustralia
3AdityaJainJapan

Query to fetch the fields Customer Name, Last Name from the table  Customer:

Example:

SELECT Customer Name,  Last Name FROM Customer;      

Output:

Customer NameCustomer Name
ShubhamThakur
PrashantChopra
AdityaJain

To retrieve all the fields from the table Customer:

Example:

SELECT * FROM Customer;

Output:

Customer IDCustomer NameCustomer NameCountry
1ShubhamThakurIndia
2PrashantChopraAustralia
3AdityaJainJapan