Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DB2 sql: where clausole : something OR (table is empty)

Posted on 2011-03-08
5
Medium Priority
?
532 Views
Last Modified: 2012-05-11
HI,
I would like to have
a condition where in which I test if an element is present
in a tableX OR the tableX is empty.
The where will return true if the element is present in tableX
BUT return true even if the tableX is empty.
How do I do?
thanks
0
Comment
Question by:bobdylan75
  • 3
5 Comments
 

Author Comment

by:bobdylan75
ID: 35069487
select * from tableA
where tableA.key in (select key from tableX) OR tableX is empty...

Is there a way like that..
0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 2000 total points
ID: 35069551

Hi Bob,

SELECT * FROM tableA
WHERE tableA.key in (select key from tableX)
  OR ((Select count(*) from tablex) = 0)


Will that work?


Kent
0
 
LVL 3

Expert Comment

by:CarlsbergFTW
ID: 35069646
Try using an outer join against the table that might have null or no value ?
0
 

Author Comment

by:bobdylan75
ID: 35070181
Thank you CarlsbergFTW,
but I think the easy way is that one of Kdo.
0
 

Author Closing Comment

by:bobdylan75
ID: 35070184
thank you!
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question