Answer the question
In order to leave comments, you need to log in
How to find records with the same fields?
Hello!
There is a table of the form: ID | Category | Field1 | .... | FieldN
In it, ID is the primary key auto-increment, Category is a certain string, the remaining fields contain some data.
For each Category, there are >=1 records that have at least a data field that is unique (within the category). I.e:
ID | Category | Field1 | ... | FieldN
1 | category1 | somedata | ... | somedata
2 | category1 | otherdata | ... | somedata
3 | category1 | somedata | ... | otherdata
4 | category2 | otherdata | ... | somedata
5 | category3 | somedata | ... | somedata
6 | category4 | unique data | ... | unique data
-- получим все возможные варианты полей в первой категории
SELECT `Field1`, ..., `FieldN` FROM `table` WHERE `Category`='category1'
-- найдём все категории, у которых поля совпадают, и которые не являются первой категорией
SELECT `Category` FROM `table`
WHERE ( `Field1` IN ( соответствующий столбец из первого запроса )
OR `FieldN` IN ( ... ) )
AND `Category`!='category1'
Answer the question
In order to leave comments, you need to log in
Somehow everything is confusing with the fields. For understanding, it is better to indicate real data.
Option 1.
If I understand correctly, it is enough to find duplicate values
SELECT Field1
FROM MyTable
GROUP BY Field1
HAVING COUNT(*) > 1
SELECT *
FROM MyTable
WHERE Field1 = ...
SELECT *
FROM MyTable MyTable1, MyTable MyTable2
WHERE MyTable1.Field1 = MyTable2.Field1 AND MyTable1.Category != MyTable2.Category
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question