user1083382
user1083382

Reputation: 849

mysql if in where clause

This is probably very easy and just I'm being thick - I'm trying to stop reserved items from being picked up in the records but only if the stock is greater than 0, I can't work out how to do an unless

"....WHERE blah blah AND (reserved = 0 OR reserved < ".(time()-1200).")"

So the column I'm looking at is called the "stock" column and if that value is 0 then I DO want to display the result

So I thought I could do

if(stock<>0,reserved = 0 OR reserved < ".(time()-1200.")

But that errors...

Upvotes: 0

Views: 583

Answers (2)

Jim
Jim

Reputation: 22656

I may have misunderstood but wont:

"WHERE blah blah AND (stock = 0 OR reserved = 0 OR reserved < ".(time()-1200).")))"

do what you need?

Upvotes: 0

Marc B
Marc B

Reputation: 360602

you can't do assignments like that in an if() clause. The format is

if (condition, true_value, false_value)

Possibly something like this will do:

if (stock <> 0, 0, time()-1200) AS reserved

Upvotes: 1

Related Questions