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 601057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:40:24+00:00 2026-05-13T16:40:24+00:00

I am using a MySQL INNER JOIN statement which returns various results for one

  • 0

I am using a MySQL INNER JOIN statement which returns various results for one distinct record in the main table from the joins, similar to How to Join Multiple Joins yet return Distinct Values
My query is

SELECT  cl.*, dep.dept_name  
FROM epapers.clientelle  cl 
INNER JOIN  epapers.dept_staff_users depu 
ON depu.user_id=cl.user_id 
INNER JOIN epapers.dept dep 
ON dep.dept_id=depu.dept_id 
group by cl.user_id 
ORDER BY cl.user_name ASC, 

I would like to display the above in a table shown below

echo "<tr bgcolor='#CCCCCC'>
<td >$num</td><td >".$row[user_id]."</td><td>".$row[user_name]."</td>
<td >".$row[fname]."</td><td >".$row[lname]."</td>
 <td >".$row[dept_name]."</td>
 <td >".$row[dept_name]."</td>
 <td >".$row[dept_name]."</td>
 <td >".$row[email]."</td>";
 $TrID = "$row[user_id]";
 echo "<td >";
 echo '<form name="activate" action="activate_acc.php" method="POST" ;">';
 echo "<input type='hidden' name='TrID' value='$TrID'>";    
 echo "<input type='checkbox' name='active' value='$row[active]'>"; 
 echo '<input type="submit" name="Submit" value="Delete">';
 echo '</form>';
 echo "</td >";
 ...

Note the the departments can be upto 3 departments. How do I return the mysql query results in a single row for the departments?

  • 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-05-13T16:40:25+00:00Added an answer on May 13, 2026 at 4:40 pm

    If you are using MySQL you can use GROUP_CONCAT but you will have to do some post processing and it’s a bit ugly.

    SELECT  cl.*, GROUP_CONCAT( DISTINCT dep.dept_name SEPARATOR '|' ) as dept_name 
    FROM epapers.clientelle  cl 
    INNER JOIN  epapers.dept_staff_users depu 
    ON depu.user_id=cl.user_id 
    INNER JOIN epapers.dept dep 
    ON dep.dept_id=depu.dept_id 
    group by cl.user_id 
    ORDER BY cl.user_name ASC
    
    
    
    foreach( ....
        $departments = explode( '|', $row['dept_name'] );
    ...
        if( isset( $departments[0] ) ) {
            echo "<td>{$departments[0]}</td>";
        } else {
            echo "<td></td>";
        }
        // same check
        echo "<td>{$departments[1]}</td>";
        // same check
        echo "<td>{$departments[2]}</td>";
    

    It’s kinda denormalisation at runtime…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 431k
  • Answers 431k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In your OnClick(), I think you must use something like… May 15, 2026 at 2:16 pm
  • Editorial Team
    Editorial Team added an answer There's no reason you can't extract the element you want… May 15, 2026 at 2:16 pm
  • Editorial Team
    Editorial Team added an answer Make two buttons with your second layout. use button1.setVisibility(View.GONE) method… May 15, 2026 at 2:16 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.