0

I want to compare 3 fields value in a table. example:column 1 - 10 items column 2 - 7 items with 3 Null column 3 - 4 items with 6 null

anybody can help me!

               items          column1    column2       column3
                  1               BK1    NULL            BK1
                  2               RK1    RK1             RK1
                  3               SK1    SK2             NULL
                  4               AK1    AK1             AK2
                  5               CK1    CK2             CK2
                  6               DK1    NULL            NULL
                  7               EK1    EK1             NULL
                  8               FK1    NULL            NULL
                  9               GK1    GK1             NULL
                  10              HK1    NULL            NULL

Reuslt

                items            column1 column2       column3  RESULT
                  1               BK1    NULL            BK1    OK
                  2               RK1    RK1             RK1    OK
                  3               SK1    SK2             NULL   NOT EQUAL
                  4               AK1    AK1             AK2    NOT EQUAL
                  5               CK1    CK2             CK2    NOT EQUAL
                  6               DK1    NULL            NULL   OK
                  7               EK1    EK1             NULL   OK
                  8               FK1    NULL            NULL   OK
                  9               GK1    GK1             NULL   OK
                  10              HK1    NULL            NULL   OK
10
  • Edit you query. Doesn't make much sense as it is now. Commented Sep 11, 2015 at 9:36
  • Add table definitions, sample data and expected outout! Commented Sep 11, 2015 at 9:40
  • We can't figure out what you are asking for without any info... Commented Sep 11, 2015 at 9:43
  • This my table look like Commented Sep 11, 2015 at 9:56
  • Great. And what's the output you want, if you have the table data as above? Commented Sep 11, 2015 at 9:57

2 Answers 2

1

I hope following can be helpful

select * from tablename            
where (column1 is not null and column2 is not NULL and column3 is not NULL)
and (column1 = column2 or column2 = column3 or column3 = column1 )

Please check SQLFiddle example http://sqlfiddle.com/#!3/fe38f/1

Sign up to request clarification or add additional context in comments.

2 Comments

It is omitting the null value items
I need query to compare the field with null value, Please see the Result in Item number 1
0
select * from tablename
where
    (c1 is null or ((c2 is null or c1 = c2) and (c3 is null or c1 = c3)))
 and
    (c2 is null or ((c1 is null or c1 = c2) and (c3 is null or c2 = c3)))
 and
    (c3 is null or ((c1 is null or c1 = c3) and (c2 is null or c2 = c3)))

1 Comment

Need to add any extra bracket

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.