How do I combine a left join with a like in Sybase SQL?
I am stuck trying to combine a like
with a left join in Sybase.
For example (although in my case it's a bit more complicated), I am looking for text that neither contains an o
nor an i
.
I am able to do the opposite, that is, text containing either of these letters:
select numbers.name from
(
select 'one' name union all
select 'two' name union all开发者_JAVA技巧
select 'three' name union all -- neither %o% nor %i%
select 'four' name union all
select 'five' name union all
select 'six' name union all
select 'seven' name union all -- neither %o% nor %i%
select 'eight' name union all
select 'nine' name union all
select 'ten' name -- neither %o% nor %i%
) numbers,
(
select '%o%' expression union all
select '%i%' expression
) patterns
where
numbers.name like patterns.expression
selects all records except three
, seven
and ten
as expected.
Now, I am looking for a way to find these three records. I thought about left joining numbers with patterns and then filtering on the expression being null. Something like this:
numbers.name *like patterns.expression and
patterns.expression is null
Obviously, this doesn't work. So, I'd be happy for any pointer given into the right direction.
For what's its worth, this is the version I am working on:
select @@version
'Adaptive Server Enterprise/15.0.3/EBF 17156 ESD#3/P/Sun_svr4/OS 5.8/ase1503/2726/64-bit/FBO/Fri Feb 5 05:26:23 2010'
You should use NOT EXISTS
(it's the case):
select numbers.name from
(
select 'one' name union all
select 'two' name union all
select 'three' name union all -- neither %o% nor %i%
select 'four' name union all
select 'five' name union all
select 'six' name union all
select 'seven' name union all -- neither %o% nor %i%
select 'eight' name union all
select 'nine' name union all
select 'ten' name -- neither %o% nor %i%
) numbers
where not exists (select null
from (
select '%o%' expression union all
select '%i%' expression
) patterns
where numbers.name like patterns.expression)
精彩评论