sql server - Advanced Sql query to identify missing data -


i dealing sql server table 'suburb' has suburb_id column , adjacent_suburb_ids column. adjacent_suburb_ids column comma separated string of other suburb_ids.

i have found of records not reciprocating -

e.g "suburba" has "suburbb" id in adjacent_suburb_ids "suburbb" not have "suburba" id in adjacent_suburb_ids

i need identify suburbs not reciprocating adjacent_suburbs, can sql query?

please not comment on data/table structure not in control , can't change it.

assuming i'm understanding question correctly, can join table using like , not like operators:

select s.suburb_id, s2.suburb_id s2id suburb s    join suburb s2 on      s.suburb_id <> s2.suburb_id     , ',' + s2.adjacent_suburb_ids + ','          '%,' + cast(s.suburb_id varchar(10)) + ',%'      , ',' + s.adjacent_suburb_ids + ',' not          '%,' + cast(s2.suburb_id varchar(10)) + ',%'  

you need concatenate comma before , after search within set. , yes, if had chance, should consider normalizing data.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -