Using SELECT Statements - SQL Query
SELECT Statements
Different ways to use SELECT statements
Select statements are used to select and view the specific record present in the table.
Consider the following table titled 'Students'.
Stud_ID | Name | Marks |
---|
1 | Jaya | 60 |
2 | Surendra | 60 |
3 | Prashant | 70 |
I) Find distinct Marks from the table 'Students'.
SELECT DISTINCT Marks FROM Students
In table, columns contains many duplicate values, so SELECT DISTINCT statement is used to list different values from the specific column.
Result:
II) Count the total numbers of Stud_ID present in the table.
SELECT COUNT(Stud_ID) FROM Students
This query will returns the total numbers of records presents in the column 'Stud_ID'.
Result:
iii) Display the top 2 records from the table 'Students'.
SELECT TOP 2 * FROM Students
This query will display the top 2 rows from the table 'Students'.
Result:
Stud_ID | Name | Marks |
---|
1 | Jaya | 60 |
2 | Surendra | 60 |
iv) Display the first student from the table 'Students'.
SELECT FIRST(Name) AS First_Student FROM Students
This query will return the first student present in the table
Result:
v) Display the Last Student From the table 'Students'.
SELECT LAST(Name) AS Last_Student FROM Students
This query will display the last student present in the table.
Result:
vi) Display the 'Name' as 'Student_Name' and 'Marks' as Student_Marks from table 'Students'
SELECT Name AS Student_Name, Marks AS Student_Marks FROM Students
Result:
Student_Name | Student_Marks |
---|
Jaya | 60 |
Surendra | 60 |
Prashant | 70 |