Re: Multiple like conditions
Posted in 2004
johnjohn-gg@triceratops.com said:
> I can't seem to find the answer to this question in the SQL docs or the
> group archives. I've even tried some experimentation without luck.
>
> I'm doing a select with multiple conditions AND'ed together. On one
> field, I'm trying to use wildcards to match one of several conditions.
> What I seem to need is a combination of "LIKE" and "IN" but that
> doesn't work.
>
> My sample select looks like:
>
> SELECT * FROM table
> WHERE foo=bar
> AND blah=bleh
> AND>
> then I want to match one of several possible combinations
> target LIKE "%AA%%01%"
> OR target LIKE "%BB%%02%"
> OR target LIKE "%CC%%03%"
>
> I've tried using parentheses to partition the OR's from the other
> conditions, and actually tried more things than I remember. I feel
> like I'm blocking on an obvious answer. Any help is appreciated.
SELECT * FROM table
WHERE foo=bar
AND blah=bleh
AND (target LIKE "%AA%%01%"
OR target LIKE "%BB%%02%"
OR target LIKE "%CC%%03%")
or
SELECT * FROM table
WHERE foo=bar
AND blah=bleh
AND target LIKE "%AA%%01%"
UNION
SELECT * FROM table
WHERE foo=bar
AND blah=bleh
AND target LIKE "%BB%%02%"
UNION
SELECT * FROM table
WHERE foo=bar
AND blah=bleh
AND target LIKE "%CC%%03%")
?
--
Bye now,
Obnoxio
"C'est pas parce qu'on n'a rien ' dire qu'il faut fermer sa gueule"
- Coluche
"I'm trying to see things your way, but I can't get my head up my ass"
- JCH
"Ogni uomo mi guarda come se fossi una testa di cazzo"
- Marco
I went to the airport to check in and they asked what I did because I
looked like a terrorist. I said I was a comedian. They said, "Say
something funny then." I told them I had just graduated from flying
school.
-- Ahmed Ahmed
sending to informix-list