yomewit
yomewit

Reputation: 1

Oracle SQL comparison between two columns?

I am trying to do comparison between two columns to find mismatches in their sequence.

Column_A and Column_B have char values and need to be compared , if Column_A and Column_B has same values irrespective of case, then RESULT col should have success, if they have different values, RESULT col should have FAIL like in 4th and 5th row

Column_A         Column_B          RESULT
------------------------------------------
 Apple           APPLE             SUCCESS
 Orange          ORANGE            SUCCESS
 Sun Flower      SUN FLOWER        SUCCESS
 Lily            LOTUS             FAIL
 Lotus           LILY              FAIL
 Olive           OLIVE             SUCCESS

I've tried the following query,

SELECT 
    Column_A, Column_B
    CASE
       IF Column_A == Column_B THEN SUCCEES
       ELSE FAIL 
    END AS RESULT 
FROM COMP_FRT;

Upvotes: 0

Views: 193

Answers (3)

The AG
The AG

Reputation: 690

SELECT column_A, column_B, CASE WHEN upper(Column_A) = upper(column_B) then 'SUCCESS' ELSE 'FAIL' END AS RESULT FROM COMP_FRT;

You can use lower or upper or INITCAP based on your comfort actually

Upvotes: 3

AGI_rev
AGI_rev

Reputation: 131

SELECT Column_A, Column_B,
CASE WHEN Lower(Column_A) = lower(Column_B) 
     THEN 'SUCCESS' ELSE 'FAIL' 
END AS RESULT 
FROM COMP_FRT;

Upvotes: 1

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 32003

it will be like below

SELECT Column_A, Column_B,
CASE when Column_A = Column_B THEN 'SUCCEES'
ELSE
'FAIL' 
END AS RESULT 
FROM COMP_FRT;

Upvotes: -1

Related Questions