Removing records from a table without a primary key

I need to delete a specific record from a database table, but the table itself does not have a primary key. Therefore, the condition depends on another table. So what is the right way to do this?

  delete from table_1 
    where exists 
         (select distinct tb.* 
          from table_1 tb, table_2 tb_2, table_3 tb_3
          where tb1.col = tb2.col
          and tb3.col = tb2.col
          and tb3.col_2= 10)

Is the right way to do this? Suppose table_1 has 4 columns, and the first two columns should be criteria for deletion.

+4
source share
1 answer

If the selected version of your query returns the results you want to delete, then you are kind. A couple of things though ..

, ANSI, , ( ). , , .

EXISTS . , : 10 .

SELECT *
FROM table_1 tb_1
WHERE EXISTS (SELECT *
              FROM table_2 tb_2
              JOIN table_3 tb_3 ON tb_2.col = tb_3.col
              WHERE tb_1.col = tb_2.col
              AND tb_3.col_2 = 10)
+2

Source: https://habr.com/ru/post/1683914/


All Articles