Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of Distinct in MySQL

Tags:

mysql

I would like to know if there is an opposite of "select distinct" in sql ,so that i can use to get values from a table of only which has repeated multiple times.

Thanks

like image 846
seeTheObvious Avatar asked Sep 14 '11 05:09

seeTheObvious


People also ask

What is opposite of distinct in SQL?

The opposite of DISTINCT is ALL. Because ALL is the default, it is typically not included.

What can I use instead of distinct in SQL?

GROUP BY is intended for aggregate function use; DISTINCT just removes duplicates (based on all column values matching on a per row basis) from visibility. If TABLE2 allows duplicate values associated to TABLE1 records, you have to use either option.

Can I use GROUP BY instead of distinct?

Well, GROUP BY and DISTINCT have their own use. GROUP BY cannot replace DISTINCT in some situations and DISTINCT cannot take place of GROUP BY.

Is distinct and GROUP BY the same?

GROUP BY lets you use aggregate functions, like AVG , MAX , MIN , SUM , and COUNT . On the other hand DISTINCT just removes duplicates. This will give you one row per department, containing the department name and the sum of all of the amount values in all rows for that department.


1 Answers

select some_column, count(*) from some_table group by 1 having count(*) > 1; 

On databases like mysql, you may even omit selecting count(*) to leave just the column values:

select some_column from some_table group by 1 having count(*) > 1; 
like image 98
Bohemian Avatar answered Sep 18 '22 15:09

Bohemian