-1

This query execution never ends.

delete from commande where bl in (
    select noBl from (
        select distinct noBl,num_commande from T_VENTE) s
    group by noBl
    having count(*)>2
);

I don't understand because the subquery

select noBl from (
        select distinct noBl,num_commande from T_VENTE) s
    group by noBl
    having count(*)>2

takes one second to achieve.

Column bl is indexed in table commande.

If someone has an idea...
Thanks in advance

thomas
  • 1,201
  • 2
  • 15
  • 35

2 Answers2

0

I am not sure what you are achieve.You need to give detailed information.
You need a conditional statement for delete is something like this.

DELETE FROM customer1 WHERE agent_code=ANY(SELECT agent_code FROM agents WHERE working_area='London');

How its work

first get records from agent_code from agents table and then result are used to perform a delete operation.

Vasim Shaikh
  • 4,485
  • 2
  • 23
  • 52
0

You have to use another level of subquery : check this answer

delete from commande where bl in (
    select noBl from (
        select noBl from (
            select distinct noBl,num_commande from T_VENTE) s
        group by noBl
        having count(*)>2
    ) as tmp
);
coytech
  • 193
  • 7