Guys I have the following tables in my DB
locations
- id (primary key)
- name
projects
- id (primary key)
- location_id (foreign key => locations)
- projectname
milestones
- id (primary key)
- name
statuses
- id (primary key)
- status
project_milestones
- id (primary key)
- project_id (foreign key => projects)
- milestone_id (foreign key => milestones)
- status_id (foreign key => statuses)
Here, For listing all the Milestones (which has status 9) of all projects, I'm using following query
SELECT projects.projectname, locations.name, DATE_FORMAT(projects.created_at, '%d-%m-%y') as projectdate,
GROUP_CONCAT(milestones.name ORDER BY project_milestones.milestone_id ASC separator '<br/>') AS milestones
FROM projects INNER JOIN locations ON projects.location_id=locations.id
INNER JOIN project_milestones ON project_milestones.project_id=projects.id AND project_milestones.status_id=9
INNER JOIN milestones ON project_milestones.milestone_id=milestones.id
INNER JOIN statuses ON project_milestones.status_id=statuses.id
AND project_milestones.milestone_id=milestones.id GROUP BY projects.projectname
Result looks like this
Location Date Created Project Name Milestones (Status 9) Bangalore 25-10-11 ABCD CSO Contacts, Developer Bangalore 11-11-11 Friday Establish, Publish list Bangalore 08-11-11 XX CSO Contacts, Assemble,Layouts
It's working great, But what I need is Another GROUP_CONCAT column say Milestones (Status 10) to display all the Milestones (which has status 10) of all projects.
Output like all Projects with [Status-9 Milestones] and [Status-10 milestones] listed. How can I do this?