我有一个查询,其中包含一个类似这样的子查询
IFNULL((SELECT id FROM mytable WHERE id = 1), 'No')
它工作正常,但我想在成功时返回字符串“是”,而不是该行的实际 id。
有没有办法覆盖它返回的值?
谢谢。
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';