I'm trying to find duplicate records in my table and I have the code to show the records but I need to modify it so that it also shows the other duplicate record. My example table is the following:
As you can see, the table (t_sen) contains duplicate records and I have this code to display the duplicate records:
$sql = "SELECT ID, PARA_NUMBER, TEXT FROM t_sen GROUP BY TEXT having count(*) >= 2";
$results = mysqli_query($conn, $sql) or die(mysqli_error());
while($row = mysqli_fetch_assoc($results)){
foreach($row as $column => $value){
print "$column: $value <br>";
}
print "<br>";
}
The output that I get is:
ID | PARA_NUMBER | TEXT
----------------------------
3 | 1 | is
7 | 2 | live
However the output that I want is:
ID | PARA_NUMBER | TEXT
----------------------------
3 | 1 | is
4 | 1 | is
7 | 2 | live
8 | 2 | live
I want it to show the other duplicate column also within the defined PARA_NUMBER. So an example (made up?) query would be something like:
SELECT ID, PARA_NUMBER, TEXT FROM t_sen (WITHIN PARA_NUMBER = 1) having count(*) >= 2
So the output should be:
ID | PARA_NUMBER | TEXT
----------------------------
3 | 1 | is
4 | 1 | is
But it would be much better if I don't have to repeat the query for every single PARA_NUMBER as there are many numbers and just one query can display all the duplicate records.
Hope I'm clear. Any help would be much appreciated.