DELETING doubled users (MySQL)

Posted by vizzdoom on Stack Overflow See other posts from Stack Overflow or by vizzdoom
Published on 2010-04-19T16:38:59Z Indexed on 2010/04/19 16:43 UTC
Read the original article Hit count: 503

Hi

I have two tables. There are users informations from two sites:
p_users
p_users2
There are 3726 users in first and 13717 in second.

Some users in p_users2 are in p_users. I want merge this two tables to the one big table - but rows with same usernames can't be doubled.

How can I do this? I tried something like this:

DELETE FROM p_users2 WHERE user_id IN 
(
select p.user_id from p_users p
join p_users2 p2 on p.username=p2.username
)

After that I should receive a table with unique usernames, which I want to export and import to the first one. But when I execute my query I got error:

SQL Error (1093): You can't specify target table 'p_users2' for update in FROM clause. (MYSQL)

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysql-query