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_IDNameMarks
1Jaya60
2Surendra60
3Prashant70

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:

Marks
60
70

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:

Stud_ID
3

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_IDNameMarks
1Jaya60
2Surendra60

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:

First_Student
Jaya

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:

Last_Student
Prashant

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_NameStudent_Marks
Jaya60
Surendra60
Prashant70