Find Unique Values
If the value in the column is repeatable, how do we find out the unique values?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Datta KharadRank #2,135 · 668 reputationPosted Nov 30, 2011, 9:20 PM EST
You can get unique values using Distinct.
Ex:- Select Distinct name from Tabname;
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 30, 2011, 9:31 PM EST
Use DISTINCT keyword.
The SELECT keyword allows us to grab all information from a column (or columns) on a table. This, of course, necessarily mean that there will be redundancies. What if we only want to select each DISTINCT element? This is easy to accomplish in SQL. All we need to do is to add DISTINCT after SELECT. The syntax is as follows:
SELECT DISTINCT "column_name"
FROM "table_name"
For example, to select all distinct stores in Table Store_Information,
Table Store_Information
store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
Los Angeles $300 Jan-08-1999
Boston $700 Jan-08-1999
we key in,
SELECT DISTINCT store_name FROM Store_Information
Result:
store_name
Los Angeles
San Diego
Boston
Thanks
Arjun PanwarRank #254 · 9.9K reputationPosted Nov 30, 2011, 10:08 PM EST
Datta KharadRank #2,135 · 668 reputationPosted Nov 30, 2011, 11:31 PM EST
Arjun PanwarRank #254 · 9.9K reputationPosted Dec 1, 2011, 2:16 AM EST
Datta KharadRank #2,135 · 668 reputationPosted Dec 1, 2011, 11:41 PM EST
Suppose you have Employee Table:-
E_Id LastName FirstName City
1 Patil Rajesh Pune
2 Kharad Datta Mumbai
3 Raut Amar Pune
In a table, some of the columns may contain duplicate values. you will want to list only the different (distinct) values in a table then you have to use keyword DISTINCT in Select SQL statement.
Distinct Syntax:-
SELECT DISTINCT column_name(s)
FROM table_name
Example:-
SELECT DISTINCT City FROM Employee
Result:-
City
Pune
Mumbai
Datta KharadRank #2,135 · 668 reputationPosted Dec 5, 2011, 1:43 AM EST