Home > database >  Is there a shorter way to write many WHERE clauses for single column in SQL?
Is there a shorter way to write many WHERE clauses for single column in SQL?

Time:06-30

I have this query:

SELECT * 
FROM users 
WHERE UPPER(column) = 'STRING1'  
   OR UPPER(COLUMN) = 'STRING2' 
   OR UPPER(COLUMN) = 'STRING3' 
   OR ... 
   OR UPPER(COLUMN) = 'ANYSTRING';

Here you can see that UPPER(column) is compared with multiple strings (strings are arbitrary). The query becomes massive as the number of strings to compare increases.

I'm wondering if there is some shorter way to write this query, maybe something like this?

SELECT * 
FROM users 
WHERE UPPER(column) = ('STRING1' OR 'STRING2' OR ... OR 'ANYSTRING')

Thanks!

CodePudding user response:

select *
from users
where upper(column) in ('STRING1', 'STRING2', ... 'ANYSTRING')
  •  Tags:  
  • sql
  • Related