Is there any shorter way to look for multiple matches:
SELECT * from table WHERE column LIKE "AAA%" OR column LIKE "BBB%" OR column LIKE "CCC%"
This questions applies to PostgreSQL 9.1, but if there is a generic solution it would be even better.
“The SQL LIKE operator allows performing logical evaluation for any matching records. Using the LIKE operator, you can specify single or multiple conditions. This allows you to perform an action such as select, delete, and updating any columns or records that match the specified conditions.
The SQL LIKE clause is used to compare a value to similar values using wildcard operators. There are two wildcards used in conjunction with the LIKE operator. The percent sign represents zero, one or multiple characters. The underscore represents a single number or character.
select * from employee where name like '%aa%' or name like '%bb% or name like '%cc%'..... Next row NAME Column Contains aa bb cc dd..... each value in the NAME column and put in the multiple like operator using OR condition.
PostgreSQL IN operator syntax You use IN operator in the WHERE clause to check if a value matches any value in a list of values. The syntax of the IN operator is as follows: value IN (value1,value2,...) The IN operator returns true if the value matches any value in the list i.e., value1 , value2 , …
Perhaps using SIMILAR TO
would work ?
SELECT * from table WHERE column SIMILAR TO '(AAA|BBB|CCC)%';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With