SQL query to find unique column values from table

We take a sample table named Geeks and return unique column values by applying various SQL queries on it.


Table – Geeks

G_ID FIRSTNAME LASTNAME JOININGDATE DEPARTMENT
1 Mohan Arora 7-08-2019 DBA
2 Nisha Verma 25-03-2017 Admin
3 Vishal Gupta 9-01-2020 DBA
4 Amita Singh 5-12-2017 Writer
5 Vishal Bharti 3-05-2018 Admin
6 Vinod Diwan 19-04-2018 Review
7 Sheetal Kumar 5-01-2017 Review
8 Geeta Chauan 5-02-2019 Admin
9 Mona Mishra 15-01-2018 Writer



SQL query to find unique values of column department from Geeks table.

Select distinct DEPARTMENT 
from Geeks;

Output –



DEPARTMENT
Admin
DBA
Review
Writer



SQL query to find details of column department where name as “DBA”.

Select * 
from Geeks 
where DEPARTMENT like 'DBA%';

Output –

G_ID FIRSTNAME LASTNAME JOININGDATE DEPARTMENT
1 Mohan Arora 7-08-2019 DBA
3 Vishal Gupta 9-01-2020 DBA



SQL query to find the count of rows in the department ‘Admin’.

SELECT COUNT(*) 
FROM Geeks 
WHERE DEPARTMENT = 'Admin';

Output –

(No column name)
3


Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.