1

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.

4
  • Mayby You've already delete them, but did not commit/rollback changes? Commented Aug 3, 2016 at 12:36
  • No this record exists.i am not beginner Commented Aug 3, 2016 at 12:37
  • Should work fine. Like was commented, you're probably not checking the results correctly or not committing, etc. If you want further help, please provide a minimal but complete script that we can use to reproduce your problem. Commented Aug 3, 2016 at 12:41
  • All these LEFT JOINs make little sense to me; you basically want an exists(). And the LEFT JOIN ... where ces.id is null can be rewitten into a not exists() And it appears you don't need the LEFT join [table5] ci on ces.car_information_id = ci.id term at all. Commented Aug 3, 2016 at 13:04

3 Answers 3

1

replace ces.id is null with nvl(ces.id,0) = 0

Sign up to request clarification or add additional context in comments.

Comments

1

i think your problem is in using "is null" in query .i do not know why happen this problem

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 nvl(ces.id,0)=0 
                   and aad.depot_ammu_estimate = 123)

Comments

0

I don't have testing env to work with syntax, but try EXIST clause. Something like this.

DELETE FROM [table1] t WHERE
EXISTS
(
  select 1
                  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 
and aad.id=t.id;
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.