2

We have shifted our project from Google app engine to Apache Tomcat. I have a case scenario in which one client (web/mobile) need to send messages to multiple people depending on task and task-age.

In Google app engine project we made this case scenario possible using endpoint. We made two pojo class one for company and another for employee, in which employee is child of company. I can declare a list of user and a getter and setter method in company pojo class to fetch a company details including all employee working in that company from datastore in single query.

Now I have to perform same thing with MySQL in which one row of company table should also have one field of employee containing information of employee (an array of employee)!!!

How do I capture multiple people (i.e., array of people name) in same filed of a MySQL table??

7
  • 3
    It's most times a bad idea to do that. Use another table and insert a row for each value. Commented Aug 16, 2014 at 12:12
  • Don't. Create a separate table, and add a foreign key. Commented Aug 16, 2014 at 12:17
  • thank you vary much for your answers @VMai and dasblinkenlight !!!what i want to ask is it is our project requirement,we dont want to spend too much of server time to process!!!can you suggest me any solution of this!!! Commented Aug 16, 2014 at 14:12
  • one solution i have knowladge is to parse array in to json string and store it as a string in DB!!!! Commented Aug 16, 2014 at 14:13
  • can i use json to parse array in to json string and store it as a string in DB? would this be a viable solution from the prospective of performance and resource utilization? Commented Aug 18, 2014 at 8:07

1 Answer 1

1

Mysql has introduced a group_concat() function a while ago. I think what you are looking for is something like this:

select
  c.id as company,
  group_concat(e.id) as employees
from
  companies c
left join
  employee e on e.company_id = c.id
group by
  e.company_id

Your result will look like:

company | employees
------------------------------------
   1     1,2,3,4
   2     5,6,7,8
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.