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 8227063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:59:36+00:00 2026-06-07T15:59:36+00:00

I have this code from another post : SELECT bar FROM (SELECT S.subcategoryname As

  • 0

I have this code from another post :

SELECT bar
  FROM (SELECT S.subcategoryname As bar, 
               C.CategoryName AS SortName,
               ROW_NUMBER() OVER (PARTITION BY C.CategoryName 
                                      ORDER BY subcategoryname) As RowNum
          FROM category C 
     LEFT JOIN subCategory S ON C.CategoryID = S.CategoryID 
        UNION ALL
        SELECT C.CategoryName As bar, 
               C.CategoryName AS SortName, 
               0
          FROM category C) foo
ORDER BY foo.SortName, RowNum

It works, but how can I retrieve more than just categoryName and subCategoryName. Is there a way to retrieve data from all columns?

enter image description here

my code:

select  * from (select s.titlu_subcerinta as bar,c.titlu_Cerinta As SortName, ROW_NUMBER() over(partition by c.titlu_Cerinta order by titlu_subcerinta) as RowNum
from cerinteProiect c left join subcerinteProiect s on c.id_cerinta = s.id_cerinta
UNION ALL
select c.titlu_Cerinta As bar, c.titlu_Cerinta As SortName,0
from cerinteProiect c
)
foo
order by
foo.SortName,RowNum
  • 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-06-07T15:59:38+00:00Added an answer on June 7, 2026 at 3:59 pm

    As OMG Ponies said, the first SELECT FROM is pulling data from foo. If you don’t return all columns from C in there, your outer query has no way to get them.

    Expand both parts of your inner query to capture the whole table, like as follows:

    SELECT * --grab everything you get in the subquery
      FROM (SELECT S.subcategoryname As bar, 
                   C.* --note how this grabs EVERYTHING in Category, as you want
                   ROW_NUMBER() OVER (PARTITION BY C.CategoryName 
                                          ORDER BY subcategoryname) As RowNum
              FROM category C 
         LEFT JOIN subCategory S ON C.CategoryID = S.CategoryID 
            UNION ALL
            SELECT C.CategoryName As bar, 
                   C.*, --this grabs everything again
                   0
              FROM category C) foo
    ORDER BY CategoryName, RowNum --both of these come from foo - no need to specify it
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Javascript code I inherited from another developer. I am very new
I have c#.net code which calls a method from another external/referenced .net assembly. This
I have this code here printf '$request1 = select * from whatever where this
i have this code from a tutorial: // Do the search and show the
I have this source code from 2001 that I would like to compile. It
I have this code that reads from XML file. It gets five strings (groupId,
Ok i have this piece of code from which i took from W3schools :-
I am using iTextSharp in VB.net. I have this piece of code from java
I have this code to update my SQL database from data in a textbox,
I have this code in my forms.py : from django import forms from formfieldset.forms

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.