469,607 Members | 2,207 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,607 developers. It's quick & easy.

simple select question

How do I ensure that I always get back 1 row for a query, even if the
table doesn't have any rows? For example, table T1 is empty. I would
always like the data from t1 if it exists.

select c1 from t1

I have tried
(select c1 from t1
union
select 'n/a' from table (values 1) as dummy)
fetch first 1 rows only

but sometimes that gives me the n/a even if there is data in T1.

help,
Eric

Nov 12 '05 #1
1 1024
elubin_nospam wrote:
How do I ensure that I always get back 1 row for a query, even if the
table doesn't have any rows? For example, table T1 is empty. I would
always like the data from t1 if it exists.

select c1 from t1

I have tried
(select c1 from t1
union
select 'n/a' from table (values 1) as dummy)
fetch first 1 rows only

but sometimes that gives me the n/a even if there is data in T1.

help,
Eric

SELECT T.* FROM SYSIBM.SYSDUMMY1
LEFT OUTER JOIN T
ON 1 = 1;

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Scott | last post: by
13 posts views Thread by LRW | last post: by
5 posts views Thread by Stephanie_Stowe | last post: by
5 posts views Thread by Tim::.. | last post: by
7 posts views Thread by Scott Frankel | last post: by
3 posts views Thread by Chrism2671 | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.