vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| ||||
| 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 |