The SQL SELECT statement is used in the SQL command and it's is used in the database to retrieve the selected data by the conditions in queries.
In the SQL select statements have wanted to select data from one or more tables by the basic syntax.
This syntax for a single table :
SELECT
columns_list or select
FROM
table_name;
Here, the columns_list are the fields that table values want to retrieves.
If we want to fetch all the data from the table then you can use the Asterix '*' and follow the syntax.
And this is the shorthand for calling all the columns in the table.
SELECT * FROM table_name;
Here I created a table named as customers in SQL Server
Here the sample table Database to Download
cust_id | cust_name | age | city |
---|---|---|---|
1 | Rahul | 18 | vellore |
2 | Anbu | 26 | chennai |
3 | Aravindh | 26 | chennai |
4 | chandra | 24 | vellore |
5 | priya | 22 | pune |
Here I get customers table to for demonstration purposes for example sample table database.
Customer Table:
customer Table |
---|
customer_Id(primary key) |
customer_name |
Age |
city |
SELECT * FROM customers;
cust_id | cust_name | age | city |
---|---|---|---|
1 | Rahul | 18 | vellore |
2 | Anbu | 26 | chennai |
3 | Aravindh | 26 | chennai |
4 | chandra | 24 | vellore |
5 | priya | 22 | pune |
SQL SELECT:
An select data from the specific columns, in the table and select data customer_name , Age,city in the customers table.
SELECT
cust_name,
age,
city
FROM
customers;
Now, Execute the code and the results is below:
cust_name | age | city |
---|---|---|
Rahul | 18 | vellore |
Anbu | 26 | chennai |
Aravindh | 26 | chennai |
chandra | 24 | vellore |
priya | 22 | pune |