SQL Query - converting the first data set to the desired format
Hi CEans,
I am stuck with a SQL query .Need few directions.
I have a query that returns rows in the form below
A B C
18184 asas 1
18184 dfdf 1
18185 qwer 2
18185 qwio 2
18186 ank 3
18187 ur 4
I need to change it to below format
A B C
18184 asas,dfdf 1
18185 qwer,qwio 2
18186 ank 3
18187 ur 4
that is for the rows having same values in column 1 and 2 ,the value in column 2 should be comma separated.
I tried using Stragg function in Oracle but could not get it.
Any directions on converting the first data set to the desired format??
Thanks ,
Ankur Luthra
I am stuck with a SQL query .Need few directions.
I have a query that returns rows in the form below
A B C
18184 asas 1
18184 dfdf 1
18185 qwer 2
18185 qwio 2
18186 ank 3
18187 ur 4
I need to change it to below format
A B C
18184 asas,dfdf 1
18185 qwer,qwio 2
18186 ank 3
18187 ur 4
that is for the rows having same values in column 1 and 2 ,the value in column 2 should be comma separated.
I tried using Stragg function in Oracle but could not get it.
Any directions on converting the first data set to the desired format??
Thanks ,
Ankur Luthra
Replies
-
ankur8819Pasting the Screen shot for more clarification
-
PraveenKumar PurushothamanDude, check this out:
select * from ankur; +-------+------+---+ | A | B | C | +-------+------+---+ | 18184 | asas | 1 | | 18184 | dfdf | 1 | | 18185 | qwer | 2 | | 18185 | qwio | 2 | | 18186 | ank | 3 | | 18187 | ur | 4 | +-------+------+---+ select A, group_concat(b) as B, C from ankur group by c; +-------+-----------+---+ | A | B | C | +-------+-----------+---+ | 18184 | asas,dfdf | 1 | | 18185 | qwer,qwio | 2 | | 18186 | ank | 3 | | 18187 | ur | 4 | +-------+-----------+---+
Hope this helps you... 😀 All the best!!! 😁 -
PraveenKumar PurushothamanI used this query!
CREATE TABLE `ankur` ( `A` int(11) NOT NULL, `B` varchar(255) NOT NULL, `C` int(11) NOT NULL, PRIMARY KEY (`B`,`C`) ) ENGINE=InnoDB ; INSERT INTO `ankur` (`A`, `B`, `C`) VALUES ( '18184', 'asas', '1' ), ( '18184', 'dfdf', '1' ), ( '18185', 'qwer', '2' ), ( '18185', 'qwio', '2' ), ( '18186', 'ank', '3' ), ( '18187', 'ur', '4' );
Hope this helps! 😀 -
ankur8819Thanks Praveen
I did it using the below query.
Select a,stragg(b),c from ankur group by a,c -
PraveenKumar Purushothaman
Awesome! 😀ankur8819Thanks Praveen
I did it using the below query.
Select a,stragg(b),c from ankur group by a,c -
RAANAcan anybody plz help me to write the query for copying data from one table into another in C#?
-
PraveenKumar Purushothaman
Bulk Copy feature of ADO.NET might help you take a look at that: #-Link-Snipped-#RAANAcan anybody plz help me to write the query for copying data from one table into another in C#? -
PraveenKumar PurushothamanThis is the simplest way to copy a table into another (new) table in the same SQL Server database. This way of copying does not copy constraints and indexes.
select * into
We can also select only a few columns into the destination table like belowfrom select col1, col2, col3 into
Use this to copy only the structure of the source table.from select * into
Use this to copy a table across two database in the same Sql Server.from select * into
Any one of the following methods can be employed to copy a table into a destination database on a different SQL Server.from 1. Data Transformation Service (DTS) â SQL Server 2000.
2. SQL Server Integration Service (SSIS) â SQL Server 2005
3. SQL Server âExport Dataâ task. â SQL Server 2000/2005
4. Create a linked Server of the destination SQL Server on the source SQL Server and then copy the table. â SQL Server 2000/ 2005.
5. We can also use My code library (SQL Server T-SQL code samples, snippets, examples, tips, tricks, stored procedures, user defined functions, VB programs): Narayana Vyas Kondreddi's home page to generate data insertion scripts and then run the insert scripts.
6. I almost forgot this 😉 you can open the source table , select the row(s), copy (ctrl + C) the row(s), open the destination table and then paste (ctrl + V) the row(s).
You are reading an archived discussion.
Related Posts
Astronomers using Chandra data have seen the giant black hole at the center of the Milky Way devouring asteroids, which may explain the frequent flares observed.
Image Credit: https://www.nasa.gov/mission_pages/chandra/news/H-12-049.html
hi guys, i finshed my B.E in 2011 with a year back. But my aggregate is low (54%). i want to make up for it by doing m.tech in a...
Android's top-rated virtual assistant has arrived on iOS.
Speaktoit, which has had 1.4 million downloads Droid downloads and a 4.5 out of 5 rating, is now available on iOS. It...
The eligibility criteria for GATE 2012 is as follows. I'm not sure whether the criteria will change in 2013 and there seems to be no official information available about it....
Fongo and Dell have tied up to offer the 'Dell Voice' service to the Canadians (as of now, hopefully). There's an Android app, an ios app and Windows desktop app...