Reputation: 552
I need to perform an SQL query to create a table which lists Quizzes with the same name. This is the query code I have so far:
$sql = "SELECT a.name, a.id FROM tests a
INNER JOIN tests b
ON a.tests = b.tests WHERE a.id <> b.id";
$result = mysql_query($sql, $conn);
However I'm not getting any results - I've made sure to manually check the database and there are definitely duplicates. Any ideas?
Upvotes: 0
Views: 173
Reputation: 263683
I think the simpliest way is to grouped then and filter it using HAVING
SELECT Name, COUNT(*) totalCount
FROM tests
GROUP BY Name
HAVING COUNT(*) > 1
Upvotes: 4