Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8609373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:52:09+00:00 2026-06-12T03:52:09+00:00

I have two tables in my database roughly laid out as below Client id

  • 0

I have two tables in my database roughly laid out as below

Client

id |  other data
1  |  data 1
2  |  data 2
3  |  data 3
4  |  data 4

Employee assigned

id  | clientid | employee
1   | 1        | Fred
2   | 1        | Jim
3   | 3        | Peter
4   | 4        | Fred
5   | 4        | Peter
6   | 4        | James

Is there a way to return the client table with all of the employee records from the employee table? Ideally I would want both the id of the row and the employee name so I don’t think I can use GROUP_CONCAT to collect more than one column. There is also no guarantee that there will always be an entry for each client in the employee table so it would need to return an empty/null result for those clients.

I have tried two ways to get this so far in php, both are pretty inefficient in one way or another.

(A) The first was to effectively make a new database connection half way through the first one to return the list of employees associated with that client id but obviously that results in a significant number of database connections being made for just one query.

(B) The second was to pull the entire employee table into an array at the beginning of the code and search through that array to pull out the rows relating to that client id which then have the employee name and row id in. Over time this is going to end up with a pretty large array being dumped into php instantly.

Is there some way of pulling this out using just a single SQL query? I’m not all that fussed how the data would come out as I am sure I could sort through it in the php at the other end, but perhaps something along the lines of

Results

id |  other data | employees
1  |  data 1     | 1,Fred;2,Jim
2  |  data 2     | 
3  |  data 3     | 3,Peter
4  |  data 4     | 4,Fred;5,Peter;6,James

If this has been asked before somewhere I apologise, but I have been searching around a bit over the last week and haven’t found all that much to help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:52:10+00:00Added an answer on June 12, 2026 at 3:52 am
    SELECT e.*, c.other_data FROM Employee e
    INNER JOIN Client c ON e.client_id = c.id
    

    So, what you end up with is all the information from both tables grabbed in one query. So, the data would be:

         id        client_id    Employee    other_data
         1             1          Fred        data 1
         2             1          Jim         data 1
         3             3          Peter       data 3
         4             4          Fred        data 4
         5             4          Peter       data 4
         6             4          James       data 4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables in my database, one for In and one for Out
I have two tables in MySql database, one is sales_order and the other is
I have two tables in my database: Company table (ID, CompanyName, CompanyUsername, CompanyPassword) Employee
i have two tables in my database one is A other one is B
I have two database tables. One table stores data for a commitment that a
I have two tables in my database : Order(OrderID, Date, ClientID) OrderItem(OrderID, ProductID, Quantity)
I have two tables in my Database. One is Department and other is Manager.
I have a problem in fetching data from mysql database tables. I have two
I have two tables in my database as following: Employee Table: Username, Name, Job,
I have two database tables containing similar data - one is the amount of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.