Results 1 to 3 of 3
  1. #1
    Join Date
    May 2003
    Posts
    40

    Unanswered: combining select staements

    Folks

    I have three select statements. I want to display q_text based on
    the respective where condition. How do i combine these three and write
    as one select statement.


    select q_text Questions from question
    where new_account_flag = '1'

    select q_text Questions from question
    where disc_account_flag = '1'

    select q_text Questions from question
    where disc_account_flag = '0'

    Remember that all the queries returns more than 1 value.


    I tried to use
    select (query1),
    (query2),
    (query3)
    but because it is returning more than one value, there is error.


    Can any suggest me any other syntax??


    Thanks

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    select [q_text Questions] from question
    where new_account_flag = '1'
    UNION
    select [q_text Questions] from question
    where disc_account_flag = '1'
    UNION
    select [q_text Questions] from question
    where disc_account_flag = '0'
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    I think it should be UNION ALL, since either condition may produce duplicate results. UNION will eliminate duplicates.

Posting Permissions

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