Home > Back-end >  Conditional WHERE statement SQL
Conditional WHERE statement SQL

Time:12-10

I'm trying to get a conditional WHERE statement but I'm not sure how to do this without using CASE WHEN.

SELECT * FROM
  `...`
WHERE (CASE WHEN product <> 'core news' THEN type <> 'video')
ORDER BY product, metric, type

CodePudding user response:

Maybe you mean this

SELECT * 
FROM yourtable
WHERE 
(
     (product <> 'core news' AND type <> 'video') 
  OR (product = 'core news') 
) 
ORDER BY product, metric, type

CodePudding user response:

If I understand you question correctly I believe you want

SELECT * FROM
  `...`
WHERE product = 'core news' OR (product <> 'core news' AND type <> 'video')
ORDER BY product, metric, type
  • Related