Return Default value if no row found -mysql

后端 未结 4 1563
心在旅途
心在旅途 2020-12-20 18:57

I\'m building query to search multiple rows from database like

SELECT 
  * 
FROM
  table1 
WHERE col1 = \'012311\' 
  OR col1 = \'0123631\' 
  OR col1 = \'0         


        
4条回答
  •  臣服心动
    2020-12-20 19:33

    SELECT
         CASE WHEN col1 = NULL THEN "NULL" ELSE col1 END AS 'col1'
    FROM table1
    WHERE
         col1 = '012311'
         OR col1 = '0123631'
         OR col1 = '091233'
         OR col1 = '092111'
    

    This might be along the lines of what you're looking for, format-wise. If col1 is NULL then return a string "NULL" (this can be substituted). If col1 is NOT NULL then return the valued result.

    Hopefully this works!

提交回复
热议问题