0

I have 3 tables, ERA, RA and LOCS

with the following columns of interests in the respective tables

  • ERA: REMOTE_ID, LOCS_KEY, CUR
  • LOCS: LOCS_KEY
  • RA: REMOTE_ID

What im trying to accomplish:

  • 1 - Get rows where CUR = 0 in table ERA ( This is easy enough to do)

  • 2 - Then Delete from:

    • LOCS: rows matching LOCS_KEY found in 1
    • RA: rows matching REMOTE_ID from 1
itsjustme
  • 1
  • 1
  • Does this answer your question? [How to write a SQL DELETE statement with a SELECT statement in the WHERE clause?](https://stackoverflow.com/questions/17548751/how-to-write-a-sql-delete-statement-with-a-select-statement-in-the-where-clause) – D M May 06 '21 at 19:38

1 Answers1

0

Based on the duplicate target I linked, you can use the following statements to delete from LOCS and RA. Be aware that unless LOCS_KEY and REMOTE_ID are unique in the table, you may be deleting multiple rows in LOCS or RA for each match in ERA.

DELETE FROM LOCS
WHERE LOCS_KEY IN (SELECT LOCS_KEY FROM ERA WHERE CUR = 0);

DELETE FROM RA
WHERE REMOTE_ID IN (SELECT REMOTE_ID FROM ERA WHERE CUR = 0);

Try it out!

D M
  • 5,769
  • 4
  • 12
  • 27