Dumping mysql table but skipping duplicated titles

Fernanditos
Fernanditos used Ask the Experts™
on
Hi,

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.
db.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007

Commented:
You coulf try this:
CREATE TABLE new_books_bok SELECT DISTINCT * FROM books_bok;

Author

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;
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 Consultant

Commented:
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;

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial