Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6825259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:00:03+00:00 2026-05-26T22:00:03+00:00

I have a query that produces the following output in a nested set structure:

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:00:04+00:00Added an answer on May 26, 2026 at 10:00 pm

    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:

    SELECT distinct 'Junior' as Database, 
           xType, 
           displayLabel, 
           child_xType, 
           child_displayLabel
    FROM MyTable
    ORDER BY displayLabel DESC, child_displayLabel ASC
    

    UPDATE:

    I’m still confused after your last comment but give this a try

    SELECT 'Junior' as Database, 
           xType, 
           displayLabel, 
           child_xType, 
           child_displayLabel
    FROM MyTable
    GROUP BY xType, displayLabel, child_xType, child_displayLabel
    ORDER BY min(lft1),  min(lft2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a select query that currently produces the following results: Description Code Price
Dear all, I have a select query that currently produces the following results: DoctorName
I have the following Query which produces the output below; SELECT TBLUSERS.USERID, TBLUSERS.ADusername, TBLACCESSLEVELS.ACCESSLEVELID,
I have the following LINQ conditional where clause query that produces a result of
Here is a silly question. Lets say I have a query that produces for
I have the following query that I am running on my database server but
I have following SQL UPDATE query: UPDATE Invoices SET Price = (SELECT SUM(Price*ProductsAndServices.Amount) FROM
I am using in C# MYsql .I have query that works if I run
I have a query that is dynamically built after looking up a field list
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.