mysql query - insert new while delete old entries

Associate
Joined
26 Nov 2004
Posts
1,480
Location
Gran Canaria
Hi

Is there a mysql query that will enter new entries into a table while remove those not included in the insert.

For example:

I wish to insert x, y, and z into a table currently containing v, w and x. Can i remove v and w without a separate delete query?

Cheers:)
 
Thanks for reply.

To update I would need first to query the db to find which of those entries I wish to insert already exist, then use them to form the where part of the query.

Ideally i'd like to insert the entries to the table and it would discard those entries not included in the query.
 
Something like that, except there would be a where condition, in this case a foreign key. So to remove everything with a particular foreign key, and replace with new entries would be great.

Thanks for your advice :)
 
Last edited:
Sorry, I didn't do a good job of explaining myself.

Table = 'tokens'

id|token
---------
6|token1
6|token2
6|token3
7|token4
7|token5
7|token6
8|token7
9|token8

delete from tokens where id = '7';
insert into tokens (id, token) values (7, token9),(7, token10),(7, token11);

Is there any way I can skip the first query?

Thanks :)
 
Thanks for reply. I can't see on duplicate working as i require in that it would leave existing tokens. The primary key is the token name, not the id which is foreign.
 
Sorry, I didn't do a good job of explaining myself.

Table = 'tokens'

id|token
---------
6|token1
6|token2
6|token3
7|token4
7|token5
7|token6
8|token7
9|token8

delete from tokens where id = '7';
insert into tokens (id, token) values (7, token9),(7, token10),(7, token11);

Is there any way I can skip the first query?

Thanks :)
 
Back
Top Bottom