The SQL SELECT Statement is a statement that allows you to select information from a database. The SELECT Statement is used to retrieve information from a database. The data returned is saved in the result-set, which is a result table. The SQL SELECT command retrieves records from one or more tables and returns them as the result set. A SELECT command gets zero or more rows from one or more database tables or views. The most frequent data manipulation language (DML) command is SELECT in most applications.
In this article, we will dive deeper into the SELECT Query in SQL according to the GATE Syllabus for (Computer Science Engineering) CSE. Keep reading ahead to learn more.
Table of Contents
What is a SELECT Query in SQL?
In SQL, the SELECT Statement is the most widely used command. In SQL, the SELECT Statement is used to get data from a database. We can get the complete table or a subset of it based on some rules. A result table, also known as the result-set, is used to hold the information returned.
With the SELECT clause of a SELECT command statement, we define the columns to be viewed in the query result and, optionally, which column headings must appear above the result table.
The database server examines the select clause, which is the first and one of the last clauses of the SELECT Statement. The reason for this is that we need to know all of the alternative columns that could be included in the final result set before we can decide what to include in it.
Sample Table:
Candidate
ID_NO | Name | Location | Mobile | Age |
D1 | RAM | Delhi | xxxxxxxxxx | 28 |
D2 | RAMESH | Gurgaon | xxxxxxxxxx | 28 |
D3 | SUJIT | Rohtak | xxxxxxxxxx | 30 |
D4 | SURESH | Delhi | xxxxxxxxxx | 28 |
Syntax:
SELECT 1_column, 2_column FROM name_of_table
1_column , 2_column: the names of the fields of a table
name_of_table: the name of the table from which we want to fetch
Thus, such a query would return all of the rows in a table with fields 1_column , 2_column.
In order to fetch the entire table or the fields in a table:
SELECT * FROM name_o_table;
The query for fetching the fields ID_NO, NAME, AGE from the table Candidate:
SELECT ID_NO, NAME, AGE FROM Candidate;
Output:
ID_NO | NAME | Age |
D1 | RAM | 28 |
D2 | RAMESH | 28 |
D3 | SUJIT | 30 |
D4 | SURESH | 28 |
In order to fetch all the fields from this Candidate table:
SELECT * FROM Candidate;
Output:
ID_NO | NAME | LOCATION | MOBILE | AGE |
D1 | RAM | Delhi | xxxxxxxxxx | 28 |
D2 | RAMESH | Gurgaon | xxxxxxxxxx | 28 |
D3 | SUJIT | Rohtak | xxxxxxxxxx | 30 |
D4 | SURESH | Delhi | xxxxxxxxxx | 28 |
Keep learning and stay tuned to get the latest updates on the GATE Exam along with Eligibility Criteria, GATE Syllabus for CSE (Computer Science Engineering), GATE CSE Notes, GATE CSE Question Paper, and more.
Also Explore,
Comments