Sql - delete when date != $date?

I was trying to delete every row where Date is different then Date
I was trying to do it like that:
mysql_query(“DELETE FROM uniqeVisitors WHERE Date NOT IN '”.$date.“'”);

And it didn’t work… What can I do so I could delete every row which is different then $date?

Feeling so dumb :X
mysql_query(“DELETE FROM uniqeVisitors WHERE Date != '”.$date.“'”);

I didnt know != works in sql…

AFAIK it only works in MySQL but is not part of the SQL standard. SQL uses <> instead of !=

IN and NOT IN are for a series.

DELETE FROM uniqueVisitors WHERE Date NOT IN ('2011-01-25', '2010-09-14')

Guys, something is not right here, NOT IN should work for a single value as well:

DELETE FROM uniqueVisitors WHERE Date NOT IN ('2011-01-25')

is equivalent to:

DELETE FROM uniqueVisitors WHERE Date != '2011-01-25'

Perhaps the problem was because the OP forgot to add parenthesis around the value after IN as it is required for proper syntax.

IN and NOT IN can accept a one-value series as well.

Yeah, a series of one value is still a series (kind of). An array with one element is still an array and a stamp collection with one stamp is still a collection, just a pretty lame one :slight_smile:

They may be lame for us humans but computers are equally serious about them as about multiple value series :).

Besides, you forgot that an array with 0 elements is also an array… :D. However, mysql will not accept a series with 0 values in IN.

Check this code

         $today = date("Y-m-d");
         $meetingremoval = mysql_query('DELETE FROM meetings WHERE date < "$today"') or die (mysql_error());

    Date < CURDATE()

Raj, welcome to the SP forums, and thank you for trying to answer questions. But do read the threads carefully first. In this case your code has nothing to do with the OP’s question, and he already resolved his problem.