Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    73

    Smile Unanswered: 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.

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    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
    ;

  3. #3
    Join Date
    Mar 2009
    Posts
    73
    Thanks so much for the reply where column1=column1 was the thing I was looking for
    Cheers !

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    sheesh, you might as well...

    1. write WHERE 1=1
    2. leave it out completely
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •