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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:31:36+00:00 2026-05-31T05:31:36+00:00

so this is my table– create table student ( stu_id int, s_name nvarchar(max), s_subject

  • 0

so this is my table–

create table student
(
stu_id int,
s_name nvarchar(max),
s_subject nvarchar(max),
marks varchar(20)
)

and the values are

insert into student values(123,'pammy','English','88');
insert into student values(123,'pammy','Maths','56');
insert into student values(124,'watts','Biology','98');
insert into student values(125,'Tom','Physics','90');
insert into student values(125,'Tom','Computer','95');
insert into student values(125,'Tom','ED','75');

so what i have done is extracted data which occurred thrice. and then concatenated the string values using sys_connect_by_path.
My code is–

 select stu_id,s_name,
max(sys_connect_by_path(s_subject, ', ' )) s_subject,
max(sys_connect_by_path(marks, ', ' )) marks

    from (select stu_id,s_name,s_subject,marks, 
                    row_number() over 
                   (partition by stu_id order by s_subject) rn
             from student
               )
   start with rn = 1
    connect by prior rn = rn-1 and prior stu_id = stu_id
    group by stu_id,s_name
having stu_id in ( select stu_id 
                    from student
                    group by stu_id 
                    having count(stu_id) >3 )
  order by stu_id,s_name

output of my code is —

stu_id      s_name  s_subject              marks
125         Tom     ,Physics,Computer,ED,    ,90,95,75,

the code is working perfectly, but I am using comma as seprator, and i just want to get rid of comma at the start and at the end. in s_subject column.

what I wants is

stu_id s_name s_subject marks
125 Tom Physics,Computer,ED 90,95,75

I tried trim function, but i could not get success.
I can substr the sys connect by path if my data is fixed, but here data is not fixed.
So pls help..

  • 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-31T05:31:36+00:00Added an answer on May 31, 2026 at 5:31 am
    SQL>  select stu_id
      2        , s_name
      3        , ltrim(max(sys_connect_by_path(s_subject, ', ' )),', ') s_subject
      4        , ltrim(max(sys_connect_by_path(marks, ', ' )),', ') marks
      5     from ( select stu_id
      6                 , s_name
      7                 , s_subject
      8                 , marks
      9                 , row_number() over (partition by stu_id order by s_subject) rn
     10              from student
     11          )
     12    where level >= 3
     13    start with rn = 1
     14  connect by prior rn = rn - 1
     15      and prior stu_id = stu_id
     16    group by stu_id
     17        , s_name
     18  /
    
        STU_ID S_NAME     S_SUBJECT                      MARKS
    ---------- ---------- ------------------------------ --------------------
           125 Tom        Computer, ED, Physics          95, 75, 90
    
    1 row selected.
    

    Regards,
    Rob.

    PS: Thanks and +1 for providing the create table statement and insert statements.

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

Sidebar

Related Questions

With this table: CREATE TABLE test_insert ( col1 INT, col2 VARCHAR(10), col3 DATE )
Considering this table: create table t (EventId int ,Section int ,PlayerName nvarchar(50) ,Score int
This table is used to store sessions (events): CREATE TABLE session ( id int(11)
Given this table design in a web application: CREATE TABLE `invoice` ( `invoice_nr` int(10)
I have this table CREATE TABLE IF NOT EXISTS `links` ( `link_id` int(20) NOT
This my table CREATE TABLE [dbo].[StandardRoom]( [StandardRoomId] [char](4) NOT NULL, [RoomType] [varchar](15) NULL, [Rate]
given this table definition create table herb.app (appId int identity primary key , application
From this table: DECLARE @tmp TABLE (id int, ahccs int, info varchar(25), endDate date)
Considering this table: create table x (id int, total int, diff int) And this
This is my table CREATE TABLE IF NOT EXISTS `results_stock_all` ( `Result_Id` varchar(50) NOT

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.