Jump to content

Recommended Posts

This query is taking about 4 seconds to run.  Can anyone help make it more efficient?  I have only a couple hundred rows in each table so it shouldn't take long at all. 

 

DELETE from sellertotals where SellerTotalNumber not in (select SellerNumber from lots WHERE LotAuctionDate = '$LotAuctionDate') AND SellerTotalDate = '$LotAuctionDate

 

This query removes any entry that has been made in the sellertotals table that doesn't match what is in the lots table for that same date. 

 

Any help would be appreciated.  Thanks.

Link to comment
https://forums.phpfreaks.com/topic/60026-solved-help-with-query/
Share on other sites

I remember a friend telling me he said using NOT IN made his queries run incredibly slow, but this was with an ACCESS database so it may be only relevant to that.

 

Personally for this I would just create two queries with one nested in the other.

DELETE from sellertotals where SellerTotalNumber not in (select SellerNumber from lots WHERE LotAuctionDate = '$LotAuctionDate') AND SellerTotalDate = '$LotAuctionDate

 

The query can be made simpler using an array to store the result of the inner query and then compare them with the result of the outer query.

DELETE from sellertotals where SellerTotalNumber not in (select SellerNumber from lots WHERE LotAuctionDate = '$LotAuctionDate') AND SellerTotalDate = '$LotAuctionDate

 

The query can be made simpler using an array to store the result of the inner query and then compare them with the result of the outer query.

 

Can someone help me with the "compare" part of the query.  I am struggling to see how I compare two results from two different queries.  Thanks for your help.

Can anyone give me an example of how I can get this code to work by not using "not in"?  I am really struggling to get this to work in a way that doesn't utilize "not in" and run efficiently.  Thanks in advance.

 

DELETE from sellertotals where SellerTotalNumber not in (select SellerNumber from lots WHERE LotAuctionDate = '$LotAuctionDate') AND SellerTotalDate = '$LotAuctionDate

I think I figured it out.  This is appears to work.  And VERY efficiently. 

 

$query = "SELECT SellerNumber FROM lots WHERE SellerNumber='$SellerTotalNumber' AND LotAuctionDate='$LotAuctionDate'";
$sellerresult = mysql_query($query) or die(mysql_error());
$sellertotalnumber=mysql_numrows($sellerresult);

mysql_close();

if ($sellertotalnumber<1)
{
include("dbinfo.inc.php");
mysql_connect("localhost",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query= "DELETE from sellertotals WHERE SellerTotalNumber='$SellerTotalNumber' AND SellerTotalDate='$LotAuctionDate'";
mysql_query($query);
mysql_close();

// echo "<BR><font size=1>$SellerTotalNumber Deleted!</font>";
}
else
{

}
}
$i++;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.