Re: Re: [PHP3] OT help with Query
| From: | Ryan Adams | Date: | Wed, 14 Jun 2000 15:26:07 +0000 |
| Subject: | Re: Re: [PHP3] OT help with Query | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-1835@lists.php.net to get a copy of this message | ||
If you're deleting from shopping_cart...
$q1 = "select shopping_cart.* from shopping_cart LEFT JOIN sessions ON
shopping_cart.user=sessions.user
where sessions.user IS NULL";
// this will select all records from shopping_cart that don't exist in sessions
$r = mysql_query ($q1);
while ($a = mysql_fetch_array ($r)) {
$q2 = "delete from shopping_cart where user='$a[user]";
mysql_query ($q2);
}
-Ryan
On Tue, Jun 13, 2000 at 07:13:14PM -0500, Richard Lynch wrote:
> In article <000701bfcf49$3644bd20$0b00a8c0@wk02>, matt@isitgone.com ("Matt
> Overall") wrote:
>
> > Does anyone know how I can run a query to delete all records from a
> table where there is not corresponding entry on another
> > table.(in mySQL)
> >
> > eg:
> >
> > DELETE ALL FROM shopping_cart WHERE shopping_cart.user NOT FOUND IN sessions.
>
> If MySQL did subqueries, you'd be damn close:
>
> delete from shopping_cart where not user in (select user from sessions)
>
> Alas, MySQL doesn't do subqueries last time I checked...
>