Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Suhi100
Starting Member
14 Posts |
Posted - 2015-02-20 : 13:15:56
|
Hi,can someone tell the logic of the below DELETE statement?It deletes all records where the file_modified column value is smaller then the maximum value in the same column, but not crystal clear how...delete a from Staging a left join (select max(file_modifieddate) as file_modifieddate from Staging) b ona.file_modifieddate = b.file_modifieddatewhere b.file_modifieddate is nullor if someone knows links to similar topics would be helpfulThanks! |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2015-02-20 : 14:32:23
|
It's due to the use of LEFT JOIN with the IS NULL option in the WHERE clause. For the joined columns in a LEFT JOIN, any rows where there wasn't a match will have a NULL value. Any rows where there was a match will have a non-NULL value. So LEFT JOIN/IS NULL is a way to get the rows that would not show up with an INNER JOIN.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
Suhi100
Starting Member
14 Posts |
Posted - 2015-02-23 : 05:20:27
|
Perfect, it is clear nowThanks |
|
|
|
|
|