M
M
metnee2014-04-16 23:03:19
MySQL
metnee, 2014-04-16 23:03:19

How can I SELECT unique records, along with the id column, but have DISTINCT ignore it when querying?

The problem is that the id column makes all records unique, and there is no point in DISTINCT * .
Something like this is needed:
SELECT (id), (DISTINCT a, b, c) FROM table
Unfortunately, group by a, b, c is too long, there are a lot of records in the database.
Help find a way out.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
1serfer, 2014-04-16
@metnee

Your ID does not participate in DISTINCT:
Remember that Distinct must always come first

H
HabRuLeX, 2014-04-17
@HabRuLeX

As an option, you can try like this:
SELECT id, p1, p2 FROM table
WHERE IN p1 IN (SELECT DISTINCT p1, p2 FROM table)
The main thing is that the set of linked fields be unique.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question