MySQL

Distinct in MySQL
Previous Home Next

The DISTINCT command is used with SELECT key word to retrieve only distinct or unique data. Sometimes, a table consist of some duplicate value (like same age values) and we want to retrieve only unique values. Here is the syntax of its command are

SELECT DISTINCT column_name
FROM  table_name;

In such scenarios ,we use the code given below:

example

SELECT DISTINCT age		//use distinct keyword in select 
FROM studinfo;			//studinfo is tablename

 

Output become

if we want more than one distinct value of two tables so the output can be shown on the basis of their row duplicacy and the code is given below as

example

SELECT DISTINCT age, sid 		//different values for output
FROM studinfo;					//studinfo is tablename

Output become

Another example is to include where condition in the above code, whose code is given below

example

SELECT DISTINCT age, sid 		//different values for output
FROM studinfo;				//studinfo is tablename
WHERE sid > 105 ;			//condition is specified

Output become

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: