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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Datta KharadPosted Dec 5, 2011, 6:43 AM
Datta KharadPosted Dec 2, 2011, 4:41 AM
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
Arjun PanwarPosted Dec 1, 2011, 7:16 AM
Datta KharadPosted Dec 1, 2011, 4:31 AM
Arjun PanwarPosted Dec 1, 2011, 3:08 AM
Satyapriya NayakPosted Dec 1, 2011, 2:31 AM
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
Datta KharadPosted Dec 1, 2011, 2:20 AM
You can get unique values using Distinct.
Ex:- Select Distinct name from Tabname;