salep
salep

Reputation: 1380

MySQL finding duplicate records with AND statement

I have a table called book. It has three columns : book_id, book_name, book_writer. When I want to find the duplicate books from the table, I can find it with the SQL query below, but there can be books with the same name that have been written by different writers. So I want to make a double check by adding the writer_name to my SQL query, but couldn't make it work. Here is my query.

SELECT book_name, COUNT(*) c FROM book GROUP BY book_name HAVING c > 1;

Upvotes: 1

Views: 46

Answers (1)

Mureinik
Mureinik

Reputation: 311843

You should add the book_writer column to the select list and the group by list:

SELECT   book_name, book_writer, COUNT(*) c 
FROM     book 
GROUP BY book_name, book_writer
HAVING   c > 1;

Upvotes: 2

Related Questions