I have a query that produces the following output in a nested set structure:
databaseName | xType | displayLabel | child_xType | child_displayLabel | lft1 | lft2
--------------------------------------------------------------------------------------------------------------------------------
Bob label Search Model name NULL NULL 252 NULL
Bob textbox productName button X 254 255
Bob label Company NULL NULL 258 NULL
Bob combobox Company comboboxItem CCCC 260 261
Bob combobox Company comboboxItem DDDD 260 263
Bob combobox Company comboboxItem HHHH 260 265
Larry label Search Model Name NULL NULL 408 NULL
Larry textbox productName button X 410 411
Larry label Company NULL NULL 414 NULL
Larry combobox Company comboboxItem DDDD 416 417
Larry combobox Company comboboxItem HHHH 416 419
The only difference between the “databases” Bob and Larry is that Bob has an extra comboboxItem called “CCCC”. What I’d like returned is a result set that combines the distinct elements of the “databases” Bob and Larry while maintaining the correct order as in the below.
databaseName | xType | displayLabel | child_xType | child_displayLabel
----------------------------------------------------------------------------------------------------
Junior label Search Model name NULL NULL
Junior textbox productName button X
Junior label Company NULL NULL
Junior combobox Company comboboxItem CCCC
Junior combobox Company comboboxItem DDDD
Junior combobox Company comboboxItem HHHH
Some notes: the result would need to appear in the exact order as in above, which is ultimately derived from the ordering of the lft1 and lft2 values in the first result set. Also, the new database “Junior” is more or less an arbitrary name for the new combined “database”.
I can imagine ways to solve this problem at the client level (rendering each item row by row), and also by pointing Larry to use the same lookups that Bob uses, but is there a way to achieve this result set using set-based SQL?
Thanks
I’m still a little unclear on what you are asking, but it appears you can get your desired result set with the following query:
UPDATE:
I’m still confused after your last comment but give this a try