Dumping mysql table but skipping duplicated titles


I have a book table (books_bok) with 3K titles. I want to dump another table (with exact same structure) but I want to avoid / skip duplicate titles.

What would be a good practice to do in this case ?

I attach the database structure in case it helps.

Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You coulf try this:
CREATE TABLE new_books_bok SELECT DISTINCT * FROM books_bok;
FernanditosAuthor Commented:
I don't think it makes much sense since you do not specify the column I want to have unique: "title_bok" ?

Do you understand what I mean? makes sense?
In that case, you could do this:

CREATE TABLE new_books LIKE books_bok;
ALTER TABLE new_books ADD UNIQUE (title_bok);
INSERT IGNORE INTO new_books SELECT * FROM books_bok;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Actually, maybe this would work (didn't test it)

CREATE TABLE new_books_bok SELECT * FROM books_bok GROUP BY title_bok;

Open in new window

theGhost_k8Database ConsultantCommented:
in case you want to have latest details for that perticular title you might use order by clause in above query:
CREATE TABLE new_books_bok SELECT * FROM books_bok GROUP BY title_bok order by id desc;
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.