• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

SQl Query

What is the correct sql query to delete from table1 column 1 where table1 column = table2 column2.
2 Solutions
Guy Hengel [angelIII / a3]Billing EngineerCommented:
delete means delete a row
you might however want only to clear a column value which would be an update

DELETE table1
FROM table1
JOIN table2
  ON table1.column = table2.column2

 --- or ---
UPDATE table1
  SET column1 = NULL
WHERE column IN  ( select column2 FROM table2 )
thenoneAuthor Commented:
so its that simple basically the join has to be called in order to make it work!!
Éric MoreauSenior .Net ConsultantCommented:
you can also do:

delete from table1
where column1 in (select column2 from table2)

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now