sql server - Comparing substrings in same table -
i need run query give me list of entries in 1 column not of entries in column, i.e.:
select distinct columna tablea columna not (select columnb tablea)
obviously, above query doesn't work, i'm providing in hopes clarify i'm trying achieve. so, example, columns contain following:
columna: abcd abce bcde bcdf bcdef ghij ghik columnb: abc def hij
my desired results be:
bcde bcdf ghik
there total of 396 values in column in table, entering values manually not feasible. in addition, noted in example, values in columnb substrings of values in columna, need have query comparison in mind.
thanks in advance can offer, , apologies if question has been answered elsewhere - did search wasn't able find interpret addressing specific requirement.
adding new info **
so, noted, made huge mistake in 2 columns in different tables. said, though, easy enough modify califax's suggestion below follows:
select distinct columna table1 t1 left join table2 t2 on t1.columna '%' + t2.columnb + '%' , t2.columnb null
however, it's still returning full list of entries columna. i've confirmed there entries in columnb substrings of entries in columna - ideas why isn't filtering?
thanks.
perform self join, , ones don't match:
select distinct a1.columna tablea a1 left join tablea a2 on a1.columna '%' + a2.columnb + '%' , a2.columnb null
(i added leading wildcard, since clarified desired matches in question.)
update
if there 2 distinct tables, b.columnb shows ones don't match:
select distinct a.columna tablea left join tableb b on a.columna '%' + b.columnb + '%' , b.columnb null
Comments
Post a Comment