Solved

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

Posted on 2011-03-08
5
522 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 45

Accepted Solution

by:
Kent Olsen earned 500 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

632 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