как-то через join делают... тут http://www.sql.ru/forum/actualthread.aspx?tid=678367
Код: Выделить всё
$c->model('DBI')->dbh->do(
'DELETE from friends
WHERE id_un = ?
AND id_un_friends = ? );
$c->model('DBI')->dbh->do(
'DELETE from friends
WHERE id_un = ?
AND id_un_friends = ? );
$c->model('DBI')->dbh->do(
'DELETE from send_friends
WHERE id_un = ?
AND id_un_friends = ? );
$c->model('DBI')->dbh->do(
'DELETE from send_friends
WHERE id_un = ?
AND id_un_friends =? );
========
========
если нужно удалить несколько записей, то тут будет вот так?
Код: Выделить всё
$c->model('DBI')->dbh->do(
'DELETE from friends AS t1,
send_friends AS t2
WHERE ( t1.id_un = ' . $c->user->{user}->{id} .'
AND t1.id_un_friends = '. $id_un.'
) OR (
t1.id_un = ' . $id_un .'
AND t1.id_un_friends = '. $c->user->{user}->{id}.'
)
OR
( t2.id_un = ' . $c->user->{user}->{id} .'
AND t2.id_un_friends = '. $id_un.'
)
OR
(
t2.id_un = ' . $id_un .'
AND t2.id_un_friends = '. $c->user->{user}->{id}.'
}' );
НО, вопрос, если в этих 2 таблицах нужно удалить несколько элементов с оператором OR правильно?
UPD: этот запрос не работает, вопрос остается, как оптимизировать? подскажите пожалуйста
была ошибка:
Код: Выделить всё
delete_friend "DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE ( t1.id_un = 33
AND t1.id_un_friends = 1
) OR (
' at line 4 at