I have the following query which is joined and left joined:
select aad.id
from [table1] aad
left outer join [table2] itm
on aad.table2_id = itm.id
left outer join [table3] eac
on aad.id = eac.table1_id
LEFT JOIN [table4] ces
ON eac.car_id = ces.id
LEFT join [table5] ci
on ces.car_information_id = ci.id
INNER join [table6] groupBi
on aad.capatibilty_degree_group_id = groupBi.id
where ces.id is null
and aad.depot_ammu_estimate = 123
The result of the above query is:
id
-----
2433
2431
Ids of [table1] table(aad.id) then I want to delete this records of that table then I query following syntax:
delete
FROM [table1] w
where w.id in (select aad.id
from [table1] aad
left outer join [table2] itm
on aad.table2_id = itm.id
left outer join [table3] eac
on aad.id = eac.table1_id
LEFT JOIN [table4] ces
ON eac.car_id = ces.id
LEFT join [table5] ci
on ces.car_information_id = ci.id
INNER join [table6] groupBi
on aad.capatibilty_degree_group_id = groupBi.id
where ces.id is null
and aad.depot_ammu_estimate = 123)
What is it happen, there are no records to delete. I don't know that what is happening that the above query does not delete the records.
LEFT JOIN ... where ces.id is nullcan be rewitten into a not exists() And it appears you don't need theLEFT join [table5] ci on ces.car_information_id = ci.idterm at all.