[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

return a many to one result set in one row in MySQL

Asked by foxymoron7 in MySQL Server, PHP and Databases

Tags: MySQL, PHP

Hi all,

I have a web based search using PHP and MySQL.  I'll use three simplified tables and an example query.  The Job table is a list of current and historical jobs performed.  The Contacts table lists all of the contacts associated with a job, employees and external contacts like clients or consultants.   The Person table is basically an "Address Book" type of table with contact info.  Below are the fields in each table that are used in the query.  The tables are existing and cannot be altered.

Job table:
Index (unique ID)
Number
Name

Job_Contact table:
Job_Index (joins to Job table)
Contact_ID (joins to Person table)
Role (defines role of contact - General Contractor, Owner, Consultant, etc.)
Title (function performed on the job, not necessarily the person's current job title)

Person table:
Contact_ID (unique ID)
Person_Name
Job_Title (person's current job title)

The Job_Contact.Title field and the Person.Job_Title field aren't necessarily equal.  When someone performs the same duty as their job title, the Job_Contact.Title field is left blank.  When they perform a duty other than their job title, that duty gets written into the Job_Contact.Title field for that specific job index and this should supercede the Person.Job_Title field in the returned results.  One of the purposes of the query is to be able to find out who did what on a specific job or to find all the jobs where a specific person performed a certain duty.

I'll attach the query and example tables in case they may be useful.

Currently the query returns something like the following when searching for job number 2009002.  John, Sue and Bob all performed the duties of "Project Manager" at some point during the job.

 Number | Name| Project Manager
   
2009002 | Apex | John, Sue
2009002 | Apex | John, Bob


I'd like to be able to return something like:

Number | Name | Project Manager
__________________________
2009002 | Apex | John, Sue, Bob

I'd like to handle it on the database side rather than scripting if possible.  Thank you in advance for any help.


1:
2:
3:
4:
5:
6:
7:
SELECT job.`Number`, job.`Name`, CONCAT(IF(contact_PM.`Contact_ID`<>'', CONCAT(person_PM.`Person_Name`, ', '), ''), person.`Person_Name`) AS `Project Manager`
FROM job
LEFT JOIN job_contact_list contact_PM ON job.`Job_Index`=contact_PM.`Job_Index` AND (contact_PM.`Title`='Sr. Project Manager' OR contact_PM.`Title`='Project Manager')  AND contact_PM.`Role`='General Contractor' 
INNER JOIN Person person_PM ON contact_PM.`Contact_ID`=person_PM.`Contact_ID`
LEFT JOIN job_contact_list contact ON job.`Job_Index`=contact.`Job_Index` AND contact.`Role`='General Contractor'
INNER JOIN person ON contact.`Contact_ID`=person.`Contact_ID` AND (person.`Job_Title`='Sr. Project Manager' OR person.`Job_Title`='Project Manager')
WHERE job.`Number`='2009002'
Attachments:
 
 
 
 
 
 
[+][-]10/30/09 02:31 PM, ID: 25706948Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: MySQL Server, PHP and Databases
Tags: MySQL, PHP
Sign Up Now!
Solution Provided By: leakim971
Participating Experts: 1
Solution Grade: A
 
[+][-]10/30/09 02:30 PM, ID: 25706940Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 02:41 PM, ID: 25707003Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625