Help me in writing query

  • I have one table name CALIMS and i want to select 2 columns

    SELECT RID ,DATE

    FROM CALIMS

    WHERE DAG='Y'

    and again want to select the data from the same same talbe without any condtions

    SELECT RID ,DATE

    FROM CALIMS

    and i want to combine the resultset ....in the final result i want the data from 1st select statement and in the second select stmt i want the data after eliminating the (1st select stmt data)

    Thanks

  • dheer (4/15/2009)


    I have one table name CALIMS and i want to select 2 columns

    SELECT RID ,DATE

    FROM CALIMS

    WHERE DAG='Y'

    and again want to select the data from the same same talbe without any condtions

    SELECT RID ,DATE

    FROM CALIMS

    and i want to combine the resultset ....in the final result i want the data from 1st select statement and in the second select stmt i want the data after eliminating the (1st select stmt data)

    Thanks

    Well this is very straightforward!

    SELECT RID ,DATE

    FROM CALIMS

    This will give you exactly what you have asked for - the result of the first query, combined with (the whole table minus the result of the first query)!

    I think you may wish to restate your requirement:-D

    Cheers

    ChrisM

    β€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Hi

    I also don't really understand the requirement. Do you mean that you want to append the filtered result with the unfiltered one? (What I still wouldn't understand πŸ˜‰ ) If yes just write "UNION ALL" between the both statements.

    Greets

    Flo

  • Florian Reischl (4/15/2009)


    Hi

    I also don't really understand the requirement. Do you mean that you want to append the filtered result with the unfiltered one? (What I still wouldn't understand πŸ˜‰ ) If yes just write "UNION ALL" between the both statements.

    Greets

    Flo

    I actually think the OP wants to use the UNION statement based on this (bolding added by me):

    .in the final result i want the data from 1st select statement and in the second select stmt i want the data after eliminating the (1st select stmt data)

    UNION will eliminate duplicate results while UNION ALL will keep duplicates (this is for the OP not you Flo, as I am sure you know this already).

  • Jack Corbett (4/16/2009)


    Florian Reischl (4/15/2009)


    Hi

    I also don't really understand the requirement. Do you mean that you want to append the filtered result with the unfiltered one? (What I still wouldn't understand πŸ˜‰ ) If yes just write "UNION ALL" between the both statements.

    Greets

    Flo

    I actually think the OP wants to use the UNION statement based on this (bolding added by me):

    .in the final result i want the data from 1st select statement and in the second select stmt i want the data after eliminating the (1st select stmt data)

    Hi Jack

    Thanks! I skipped the part with the elimination. So the UNION is the correct (or as Chris already posted just the query without any criteria πŸ˜‰ ).

    Greets

    Flo

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply