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

  • Home
  • SEARCH
  • 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 6865699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:05:12+00:00 2026-05-27T03:05:12+00:00

I have a table like: ——————- id class name sub ———————— 1 mca aditya

  • 0

I have a table like:

-------------------
id  class name      sub 
------------------------
1   mca   aditya    network
2   mca   abhishek  daa
3   mca   akhilesh  algorithm
4   btech ram       cs
5   btech shyam     ds
6   btech anand     client/server
7   mba   furqan    os
8   mba   arvind    marketing
9   mba   aayush    hr

I want a result set like the following:

----------------
class    name      sub
------------------------
mca      aditya    network
         abhishek  daa
         akhilesh  algorithm
btech    ram       cs
         shyam     ds
         anand     client/server
mba      furqan    os
         arvind    marketing
         aayush    hr
  • 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-27T03:05:12+00:00Added an answer on May 27, 2026 at 3:05 am

    I think you may be better off handling this in your UI / Display tier, but if you need the query to do it in SQL 2008, you can use a CTE with ROW_NUMBER()

    WITH ordered AS
    (
       SELECT t.class, t.name, t.sub
          , ROW_NUMBER() OVER (PARTITION BY t.class ORDER BY t.Name ASC) AS RowNumber
       FROM myTable AS t
    )
    SELECT CASE 
              WHEN o.RowNumber = 1 THEN o.class
              ELSE ''
           END AS class
       , o.name, o.sub
    FROM ordered AS o
    

    I’m not sure what sort / order you’re looking for. Your example appears to still be ordered by Id. If you want this, you can add the Id column into the ordered CTE and then add ORDER BY o.Id ASC at the end of the query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table like this: id | name | class | marks 1
I have a table like so <table> <tr id=trRow1 runat=server style=display: none> <td>First Name:</td>
I have a table like this: name code group john 12 smith 15 how
i have a table like this one: -------------------------------- id | name -------------------------------- 1 |
I have table like below id, employee_no, survey_no, name 1 test 1 test_name 2
I have table like this ------------------------------------------------------------------- id | title | image | name |
I have table like that : <table id=table_id class=tablesorter> <thead> <tr class=trheader> <th colspan=2>111</th>
I have a table like this: Item { int ItemID int ParentID string Name
I have a table like this: <table id=tbl> <tr><th>My Table</th></tr> <tr><td><div class=arrow></div></td></tr> <tr><td>The second
I have a table like following,' <table id=online_seat> <tbody id=row_B class=selected> <tr class=seat_01 B

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.