23

Having

Company
id      Name
1       Enron
2       Walmart

Employee
id      Company
2       1
3       1
4       2
5       2
6       2

I want to get

Enron 2,3
Walmart 4,5,6

so far I wrote:

select Company.Name, Employee.id
from Company inner join Employee
on Company.id = Employee.Company 
group by Company.id

but the current result is

Enron 2
Walmart 4

1 Answer 1

37

Use Group_Concat:

select Company.Name, Group_Concat(Employee.id)
from Company inner join Employee
on Company.id = Employee.Company 
group by Company.id
Sign up to request clarification or add additional context in comments.

Comments

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.