Reputation: 4459
I have about the following query:
SELECT *
FROM Product
ORDER BY (SELECT CASE
(SELECT MIN(date) FROM SomethingElse WHERE productId = Product.id) AS here
WHEN NULL
THEN 0
ELSE here
) DESC
However, AS in CASE doesn't work. I need a way to save the value in a variable and use it again.
Upvotes: 1
Views: 189
Reputation: 453328
So you are trying to do CASE when expression IS NULL THEN 0 ELSE expression END
?
In this case you can just use COALESCE(expression, 0)
Upvotes: 4