Solved

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

Posted on 2011-03-08
5
503 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 45

Accepted Solution

by:
Kdo 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dynamic Query Need 9 80
Fill Field in Displayfile with variable name 7 105
AS400 CPU allocation 3 105
iSeries Backup 3 22
November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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