Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 (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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now