0

I have a table that contains the following type of data

Device     IDs
ABC        123
ABC        234
ABC        345
XYZ        123
XYZ        999

My SQL String that I was given (sorry I know nothing about SQL) was

SELECT*
From Name123456789

When I import data into the tracking application I have it produces errors because ABC and XYZ are not viewed as a Parents to the IDs but instead they are viewed each as their own individual records.

Is there a way with SQL to break it out so that Device would equal ABC and IDs would equal 123, 234, 345?

Desired Output ALL RECORDS BUT HAVE THE FOLLOWING format for just those two fields as there are other fields too:

Device     IDs
ABC        123, 234, 345
XYZ        123, 999
8
  • SELECT* From Name123456789 - all it does is select ALL rows from a table called name123456789. For starters that SQL Query is probably wrong. Commented Jul 25, 2014 at 19:09
  • logixologist Thank you. imagined that was the case. So I am looking for a way to select all rows in the table name123456789 but would like to move the IDs as a child to Device. Is this possible? Commented Jul 25, 2014 at 19:11
  • Please update the question with desired output. Its a little confusing what you are asking for. Commented Jul 25, 2014 at 19:13
  • logixologist, Thank you. I updated. Commented Jul 25, 2014 at 19:16
  • what rdbms is this in? Commented Jul 25, 2014 at 20:20

1 Answer 1

0

I have (once, a while ago) done something like this in Oracle SQL using the wm_concat function. The syntax there would be something like

select device,
       wm_concat(IDs) IDs
from tablename
group by device;

I don't use SQL server but this answer appears to show how to do the same in SQL Server.

Alternatively you could add an order by device then put the info from each device together in the application layer.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.