recursive query - using UNION together with WITH statement in SQL -
i have location table. each location stored in table tree. records can sublocation of other location , on.
in location table, execute following tsql produce locations sublocations
with locationtree ( select l.* location l union select l.* locationtree lt, location l l.parentlocationid = lt.locationid ) select * locationtree but gives me error:
recursive common table expression 'locationtree' not contain top-level union operator. the error says have use union all insead of union union all returns repeated rows. want select distinct rows when using union only.
how can use union keyword within with statement in sql?
add union all instead of union , select distinct * locationtree in outer select.
Comments
Post a Comment