If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Select where column result = all ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-07-09, 00:07
asp_crazy_guy asp_crazy_guy is offline
Registered User
 
Join Date: Mar 2009
Posts: 73
Smile Select where column result = all ?

Hi,
I have a situation where I have to make a report on basis of some parameters. The report should be able to display certain or all columns on basis of a single query.

There query can be

select * from table1 where column1='somevalue'


or

select * from table1 where column1=* ?
--- (all values in that column)

How can I select all column values by the where clause ?

Can this be done in DB2 with a single query without the need to use if else statements and 2 separate queries ?

Best regards,
Mike.
Reply With Quote
  #2 (permalink)  
Old 07-07-09, 00:48
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
select * from table1 where column1='somevalue'

or

select * from table1 where column1=* ? --- (all values in that column)
To choose first or second query, this may give equivalent results.
(The row which column1 is null would not be selected.)
Code:
select *
  from table1
 where column1 = CASE
                 WHEN <condition to select somevalue> THEN
                      'somevalue'
                 ELSE column1
                 END
;
Reply With Quote
  #3 (permalink)  
Old 07-07-09, 02:49
asp_crazy_guy asp_crazy_guy is offline
Registered User
 
Join Date: Mar 2009
Posts: 73
Thanks so much for the reply where column1=column1 was the thing I was looking for
Cheers !
Reply With Quote
  #4 (permalink)  
Old 07-07-09, 07:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
sheesh, you might as well...

1. write WHERE 1=1
2. leave it out completely
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On