I have a statement that is:
ORDER BY IFNULL(rrp, wholesale) ASC
...but I wanted to know if there开发者_如何学Python is a way to have an IFNULL
statement that checks 3 or 4 or 5 columns? All from the same table.
Use COALESCE
e.g:
SELECT ....
FROM ....
ORDER BY COALESCE(rrp, wholesale, column3, column4)
You could chain them up, so the expression picks the first not-null value from a list of columns:
ORDER BY IFNULL(IFNULL(IFNULL(rrp, wholesale), some_column), some_other_column) ASC
Try using COALESCE
; it may give you what you need.
精彩评论