Ok, I was having some trouble accomplishing this and, quite frankly, don't even know if it is possible to do what I want.
I have the following table structure: Table Structure
Tags (t)
============
ID
LINE_ID
TAG
ACTIVE
Dashboard Lines (dl)
===============
ID
LINE_ID
GAUGE_TAG_ID
DISPLAY_NAME
ACTIVE
Dashboard Points (dp)
================
ID
DASHBOARD_ID
TAG_ID
DISPLAY_NAME
What I am trying to do is pull all of the t.TAG into a single result based on all of the IDs in the 'Dashboard Points' table. The one exception is the GAUGE_TAG_ID in the Dashboard_Lines table. I also need to pull that tag as well. I have been able to successfully pull all of the t.TAG into a single result joining on dp.TAG_ID = t.ID. Unfortunately I have not figured out how to also include joining on the dl.gauge_tag_id to get the correlating t.tag associated with the ID.
My current query (not pulling the gauge_tag_id)
SELECT GROUP_CONCAT(DISTINCT t.TAG), dl.gauge_tag_id, dl.line_id
FROM tags t
JOIN dashboard_lines dl ON dl.line_id = t.line_id
JOIN dashboard_points dp ON dp.tag_id = t.id AND dp.dashboard_id = dl.id
WHERE t.line_id = '1'
AND t.active = 'Y'
This successfully groups all the t.TAG with correlating idson t.ID and dl.TAG_ID
Is it possible to also include the t.TAG for the dl.GAUGE_TAG_ID?
Edit: http://sqlfiddle.com/#!9/ace98d
Edit 2: Desired Results:
GROUP_CONCAT(t.TAG)
Line1_Over_Cnt, Line1_Case_Count, Line1_MaxCap..
(all the correlating tag_ids along with the gauge_tag_id -- displayed as the t.TAG)
This doesn't have to be all in one column (GROUP_CONCAT). It can be a traditional result set with all of the t.TAG so long as it includes all of them (the dp.TAG_ID on t.ID) and (dl.GAUGE_TAG_ID on t.ID)
TAG
Line1_Over_Cnt
Line1_Case_Count
Line1_MaxCap
Line1_Idle
Kleins_Line1_Reset
L1_STD_Rate
Line1_Rate_Temp
Line1_Rate
Edit3: Possible Solution
SELECT t1.tag
FROM tags t1
JOIN dashboard_lines dl ON dl.line_id = t1.line_id
JOIN dashboard_points dp ON dp.tag_id = t1.id AND dp.dashboard_id = dl.id
WHERE t1.line_id = '1'
AND t1.active = 'Y'
UNION
SELECT t2.tag
FROM tags t2
JOIN dashboard_lines dl ON gauge_tag_id = t2.id AND dl.line_id = '1'
WHERE t2.line_id = '1'
AND t2.active = 'Y'
This gives me all the tags listed in individual rows. Is this the best way? Is there a way to get them all into a single, concatenated result?
-- End edits --
Any help is appreciated, thanks.