What is SQL SELECT Statement?

The SQL SELECT statement is used to fetch the data from a database table which returns this data in the form of a result table. These result tables are called result-sets.




 SQL SELECT Statement

The SELECT statement is the most commonly used command in Structured Query Language. It is used to access the records from one or more database tables and views. It also retrieves the selected data that follow the conditions we want.

By using this command, we can also access the particular record from the particular column of the table. The table which stores the record returned by the SELECT statement is called a result-set table.

OR

The SQL SELECT statement is used to fetch the data from a database table which returns this data in the form of a result table. These result tables are called result-sets.

Syntax of SELECT Statement in SQL

SELECT Column_Name_1, Column_Name_2, ....., Column_Name_N FROM Table_Name;

In this SELECT syntax, Column_Name_1, Column_Name_2, ….., Column_Name_N are the name of those columns in the table whose data we want to read.

If you want to access all rows from all fields of the table, use the following SQL SELECT syntax with * asterisk sign:


SELECT * FROM table_name;  

Examples of SELECT Statement in SQL

Here, we took the following two different SQL examples which will help you to execute the SELECT statement for retrieving the records:

Example 1:

Firstly, we have to create the new table and then insert some dummy records into it.

Use the following query to create the Student_Records table in SQL:

CREATE TABLE Student_Records   
(  
Student_Id Int PRIMARY KEY,    
First_Name VARCHAR (20),    
Address VARCHAR (20),    
Age Int NOT NULL,  
Percentage Int NOT NULL,  
Grade VARCHAR (10)   
) ;  

The following query inserts the record of intelligent students into the Student_Records table:


INSERT INTO Student VALUES (201, Akash, Delhi, 18, 89, A2),   
(202, Bhavesh, Kanpur, 19, 93, A1),  
(203, Yash, Delhi, 20, 89, A2),    
(204, Bhavna, Delhi, 19, 78, B1),  
(05, Yatin, Lucknow, 20, 75, B1),  
(206, Ishika, Ghaziabad, 19, 51, C1),  
(207, Vivek, Goa, 20, 62, B2);  

The following SQL query displays all the values of each column from the above Student_records table:


SELECT * FROM table_name;

The output of the above query is:

Student_ID First_Name Address Age Percentage Grade
201 Akash Delhi 18 89 A2
202 Bhavesh Kanpur 19 93 A1
203 Yash Delhi 20 89 A2
204 Bhavna Delhi 19 78 B1
205 Yatin Lucknow 20 75 B1
206 Ishika Ghaziabad 19 91 C1
207 Vivek Goa 20 80 B2

Post a Comment

0 Comments

close