Discussion:
How to delete multiple rows from a single table
i***@public.gmane.org
2007-10-13 17:17:39 UTC
Permalink
hey everybody , got a question ...

How can you delete in one sql query multiple rows from a table,
something like "delete from table where id in (1, 2, 3)"
Cuz it would be quite crappy if you have 100 000 rows to delete from
one single table, and fo rthis you owuld have to send 100 000 queries
to the sql server ...


Thx a lot!
nate
2007-10-13 21:50:29 UTC
Permalink
Cake 1.2:

$this->Model->deleteAll(array('Model.id' => array(1, 2, 3)));
Post by i***@public.gmane.org
hey everybody , got a question ...
How can you delete in one sql query multiple rows from a table,
something like "delete from table where id in (1, 2, 3)"
Cuz it would be quite crappy if you have 100 000 rows to delete from
one single table, and fo rthis you owuld have to send 100 000 queries
to the sql server ...
Thx a lot!
i***@public.gmane.org
2007-10-14 00:14:16 UTC
Permalink
Thx for the tip, but how would you handle that in a version before
1.2 ... because i am kinda reluctant to jump right ahead and use it on
my production server as it's still in alpha ..
Post by nate
$this->Model->deleteAll(array('Model.id' => array(1, 2, 3)));
Post by i***@public.gmane.org
hey everybody , got a question ...
How can you delete in one sql query multiple rows from a table,
something like "delete from table where id in (1, 2, 3)"
Cuz it would be quite crappy if you have 100 000 rows to delete from
one single table, and fo rthis you owuld have to send 100 000 queries
to the sql server ...
Thx a lot!- Hide quoted text -
- Show quoted text -
CakeONaut
2007-10-14 00:31:20 UTC
Permalink
in SQL if you wanted to delete everything you could do

delete from tablenamehere where id>0

or delete from tablenamehere where someconditiongoeshere if you want
just certain rows to be expunged.

-Will
i***@public.gmane.org
2007-10-14 01:36:38 UTC
Permalink
Well .. duhhh .... of course ...
But i wanted to use cake's db abstration layer and model features...
because if i wanter to run a direct query i would just use Model-
query()
Thx anyway
in SQL if you wanted to delete everything you could do
delete from tablenamehere where id>0
or delete from tablenamehere where someconditiongoeshere if you want
just certain rows to be expunged.
-Will
nate
2007-10-14 15:24:08 UTC
Permalink
Cake 1.1 has no facilities for deleting multiple records in a single
query, other than the query() method.
Post by i***@public.gmane.org
Well .. duhhh .... of course ...
But i wanted to use cake's db abstration layer and model features...
because if i wanter to run a direct query i would just use Model-
query()
Thx anyway
in SQL if you wanted to delete everything you could do
delete from tablenamehere where id>0
or delete from tablenamehere where someconditiongoeshere if you want
just certain rows to be expunged.
-Will
Loading...