MySQL IFNULL question
Asked Answered
O

2

18

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

IFNULL((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.

Oriana answered 27/1, 2010 at 12:40 Comment(0)
C
31
IFNULL((SELECT 'Yes' FROM mytable WHERE id = 1), 'No')
Cremona answered 27/1, 2010 at 12:43 Comment(0)
H
1

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';
Hermia answered 6/5, 2013 at 18:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.