Ask Your Question
0

Delete records from one table when entered in to another in base

asked 2017-11-04 12:08:32 +0200

GarethT gravatar image

I'm pretty new to SQL in base, I've got a few queries set up now with a little help (thanks JohnSUN) which is great. I'm now exploring and have successfully used the DELETE FROM command for removing multiple entries from a table but would like to go a little further.

Rather than individually deleting rows by using.. DELETE FROM "table" WHERE "Column" = '1234' I'd rather delete entries from the first table by matching entries from a column in a second table. I've had a good go but don't yet have a good enough grasp of sql to figure it out for myself.

Hopefully thats clear and thanks in advance to anyone who can help

edit retag flag offensive close merge delete

Comments

1

If JohnSUN's answer helped then please click the checkmark on that answer. Otherwise, why should anyone spend time on this new question?

Jim K gravatar imageJim K ( 2017-11-04 15:46:05 +0200 )edit

I think what Jim K is trying to say, is that a thank you goes a long way here, as all questions are answered by volunteers. The best way to thank someone here is to up-vote their answer. There are two ways to do this, first you can click on the check box in the circle to say that this answer is the, or the best, answer for you. Also you can check the up arrow (in the vertical ^ # v set to the left of the answer's title.

EasyTrieve gravatar imageEasyTrieve ( 2017-11-04 17:48:36 +0200 )edit

I missed that checkmark and have corrected it accordingly

GarethT gravatar imageGarethT ( 2017-11-04 23:55:34 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-11-04 19:25:48 +0200

Ratslinger gravatar image

Hello,

You don't provide much information on what conditions you are trying to satisfy 'by matching entries from a column in a second table. ' There are many examples around which may help

how-to-delete-records-in-one-table-based-on-the-values-in-another-table

similar concept

Just a small sample of what is already available with a simple search.

Also, you do not state what database you are using. This can make a difference in the SQL used.

edit flag offensive delete link more

Comments

I agree its not a particularly well written question having looked back at it (probably not best off writing it whilst tired). I'll look over what you've posted tomorrow. Thanks for taking the time to point me somewhere at least though.

GarethT gravatar imageGarethT ( 2017-11-04 23:59:39 +0200 )edit

If you still have a problem after viewing links, please post additional info - DB used & exactly what determines if a record is to be deleted would be of great help.

Ratslinger gravatar imageRatslinger ( 2017-11-05 00:15:02 +0200 )edit

Still struggling, I have next to no experience with this kind of thing so please bear with me. I have two tables that both have a column called Tag. The first by necessity can have multiple records with the same tag number whilst the second allows no duplicates. Once a series of tag numbers is entered in to the second table, I'd like to be able to run an sql command to remove all rows with matching tag numbers from table one as they are no longer required there. Hopefully thats clearer

GarethT gravatar imageGarethT ( 2017-11-05 11:52:02 +0200 )edit
1

When it comes to deleting records you really need to be certain of what is to be deleted. Are you stating that if a tag exists in table "B", all records in table "A" containing that tag should be deleted? If so:

DELETE FROM TABLEA WHERE TAG IN (SELECT TAG FROM TABLEB)

should work. Like any other test, make a backup copy first to insure this is actually the result wanted.

Ratslinger gravatar imageRatslinger ( 2017-11-05 14:57:23 +0200 )edit

DELETE FROM TABLEA WHERE TAG IN (SELECT TAG FROM TABLEB)

Thats exactly what I was after so I've marked the question as answered Many thanks.

GarethT gravatar imageGarethT ( 2017-11-05 17:39:42 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-11-04 12:08:32 +0200

Seen: 323 times

Last updated: Nov 04 '17