Vinoth S
Vinoth S

Reputation: 33

MYSQL - Find the column has distinct values or not..?

I have a table in mysql-4.1.22 with huge set of data. And I want to check whether the particular column in my table has distinct values or not(No need to retrieve all distinct values). I have googled and try MYSQL inbuilt function distinct and alternative group by solution but both takes too much amount of time to execute.

Is there any other way to find a column has distinct values or not? . Kindly share your ideas.

Upvotes: 2

Views: 1123

Answers (2)

Sandeep Nanda
Sandeep Nanda

Reputation: 1

select count() from group by having count()>1;

Upvotes: 0

vyegorov
vyegorov

Reputation: 22865

SELECT count(*), count(colname), count(distinct colname)
  FROM tabname;
  1. First count() will give you total number of rows in the tabname;
  2. Second one will give you the number of NOT NULL values in you desired colname;
  3. And the last one will give you a number of distinct values in the desired colname.

Upvotes: 3

Related Questions