E
E
elailasou2015-04-03 12:03:52
MySQL
elailasou, 2015-04-03 12:03:52

MySQL, query, same values?

There is a table 'orders', type:
id | coords
------------
1 | 15
2 | 15
3 | 1
4 | 15
5 | 8
You need to display lines with the same values ​​and id, ie in this case:
1 | 15
2 | 15
4 | 15
When using GROUP BY, id collapse

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Melkij, 2015-04-03
@junk1114

select id, coords from orders join (
select coords from orders group by coords having count(0)>1
) nonuniqcoords using(coords)

A
Armenian Radio, 2015-04-03
@gbg

order by coords

I
IceJOKER, 2015-04-03
@IceJOKER

Maybe not quite the right solution, but still:
Other solutions:
stackoverflow.com/questions/688549/finding-duplicate...
stackoverflow.com/questions/854128/find-duplicate-...

X
xibir, 2015-04-03
@xibir

Without 'group by' and using aggregate functions (should be faster):
select * from orders t1 where exists
(select 1 from orders t2 where t1.id != t2.id and t1.coords = t2.coords);
The stackoverflow links above have a similar answer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question