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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -