Higher Quality
Higher Quality

Reputation: 3

SQL If one column has a desired value then check the next column

Name  SCRE_TXT  SRCE_NBR
MAX    PHONE          10
MAX    EMAIL          20
MAX    ADDRESS        90
MAX    PHONE          88
MAX    PHONE          30
MAX    EMAIL          21
MAX    PHONE          30

How would I check if the SRCE_NBR is distinct for only the rows with phone in it. Otherwise don't check SRCE_NBR at ALL.

Desired output would be

Name  SCRE_TXT  SRCE_NBR
MAX    PHONE          10
MAX    EMAIL          20
MAX    ADDRESS        90
MAX    PHONE          88
MAX    PHONE          30

Upvotes: 0

Views: 57

Answers (1)

user1515791
user1515791

Reputation:

Can you first select all the Phone rows, using distinct and then union that result with all the rows that are not Phone rows?

Select distinct * from ... where SCRE_TXT = 'PHONE'
UNION ALL
Select * from ... where SCRE_TXT <> 'PHONE'

Upvotes: 1

Related Questions