0

Table devices:

Name: Router1
Type: NODE
Class: Main

Name: Router1
Type: IF
Class: T1 0/0/1

Name: Router1
Type: IF
Class: Fa 0/1

The above is a minimal example.

The output I desire is:

Router1 | T1 0/0/1, Fa 0/1

Is this possible without creating temp tables, procedure, or a script?

I've thought deeply, but in the real world example there are multiple devices I need their IFs class from. You cannot just pull each device in any way I know.

1
  • you condition is to group them by type "IF"? Commented May 11, 2015 at 9:26

1 Answer 1

2

You can use GROUP_CONCAT on class column while group them according to name

SELECT Name, GROUP_CONCAT(class)
FROM devices
GROUP BY Name
WHERE Type= 'IF'
/*WHERE Name = 'Router_1'*/
Sign up to request clarification or add additional context in comments.

5 Comments

No way to do this for every device in the database? I know you can do it that way, but say there are 100 devices with all different IFs? I tired a sub-query.
Now this will work for all generllay test it, i have updated the answer @KirsKringle
Man I had that but without GROUP BY and I was racking my brain what is wrong with me. I can't believe I couldn't think of that. Thank you.
you condition is to group them by type?
@KirsKringle my pleasure, i have added where clause for 'Type' also, you and upvote and accept it as an answer if it helps :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.