Loading

SQL SELECT Statement

The SELECT statement in SQL is used to fetch data from one or more tables in a database. It is one of the most commonly used commands in SQL and forms the foundation of data retrieval.


Syntax


SELECT Customer Name, Last Name FROM Customer;

  • column1, column2, ... : These are the columns to retrieve

  • table_name : The name of the table from which data is retrieved


Key Points

  • SELECT is used to retrieve data

  • Use * to select all columns

  • Use a comma to separate multiple columns

  • The WHERE clause can be used to filter rows (not covered in this post)






To fetch all columns from a table:

SELECT * FROM table_name;

The asterisk * means all columns will be selected.


Examples: -  SELECT * FROM CUSTOMER;


Query Result

Customer IDCustomer NameCustomer NameCountry
1ShubhamThakurIndia
2PrashantChopraAustralia
3AdityaJainJapan


Example Queries

1. Select specific columns

To fetch only Customer Name and Last Name:


Example:

SELECT Customer Name,  Last Name FROM Customer;      

Output:

Customer NameCustomer Name
ShubhamThakur
PrashantChopra
AdityaJain


2. Select all columns

Example:

SELECT * FROM Customer;

Output:

Customer IDCustomer NameCustomer NameCountry
1ShubhamThakurIndia
2PrashantChopraAustralia
3AdityaJainJapan


Two-Minute Drill

1. Which keyword is used to fetch data from a table?

Ans: SELECT


2. What does SELECT * mean?

Ans: Select all columns from the table


3. What will this query return?

SELECT Last Name FROM Customer;
Ans: Only the Last Name column from the Customer table


4. How do you select two columns, say Name and Country?

Ans: SELECT Name, Country FROM table_name;