开发者

MySQL IFNULL question

开发者 https://www.devze.com 2022-12-18 01:29 出处:网络
I have a query which contains a subquery which is something like this IFNULL(开发者_如何学JAVA(SELECT id FROM mytable WHERE id = 1), \'No\')

I have a query which contains a subquery which is something like this

IFNULL(开发者_如何学JAVA(SELECT id FROM mytable WHERE id = 1), 'No')

It works OK, but I would like to return the string 'Yes' on success rather than the actual id of the row.

Is there any way to override the value it returns?

Thanks.


IFNULL((SELECT 'Yes' FROM mytable WHERE id = 1), 'No')


Little Advance example of IFNULL:

Problem: How to get the home phone number if office phone number is not available ?

Solution:

SELECT IFNULL(office_phone_no,home_phone_no) as contact_number
FROM employee_table e
where e.username = 'sumoanand';
0

精彩评论

暂无评论...
验证码 换一张
取 消