then the application should check for the case of no rows returned, not for a specific value. But
if you insist and use MySQL 4.1 (as subqueries are assumed):
SELECT IFNULL((SELECT nameColumn FROM theDatabase WHERE rowId = 5), 0); Which is not to say that I think this is a good idea :-)
/Karlsson John Mistler wrote:
Thanks for the reply. There is a slight difference in what I need from the "IFNULL" function. It will only return the specified value if the column is null on a row that actually exists. I am needing a function that will return the specified value if the row does NOT exist. Any other ideas?
SELECT nameColumn from theDatabase WHERE rowID = 5;
(when no row has ID "5")
result --> empty set (I want a value like '0' or something)
Thanks again!
-John
on 10/10/04 8:12 PM, liang lei at [EMAIL PROTECTED] wrote:
--- John Mistler <[EMAIL PROTECTED]>
http://lists.mysql.com/[EMAIL PROTECTED]Is there a way to force SOME value to be returned from a SELECT query when the result is empty set? For instance:
SELECT nameColumn from theDatabase WHERE rowID = 5;
(when no row has ID "5")
result --> empty set
I would like for it to return some value, such as '' or 0 . . .
Thanks,
John
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
select ifnull(column,'0') from table
_________________________________________________________
Do You Yahoo!?
150??MP3????????????
http://music.yisou.com/
???????????????????
http://image.yisou.com
1G??1000???????????
http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/
-- __ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / Anders Karlsson ([EMAIL PROTECTED]) / /|_/ / // /\ \/ /_/ / /__ MySQL AB, Sales Engineer /_/ /_/\_, /___/\___\_\___/ Stockholm <___/ www.mysql.com Cellphone: +46 708 608121
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]