Posted: 07/10/2011, 8:46 PM |
|
rbroder,
Here you go ( was done in MySQL 5.0.51a):
MasterTable:
MasterID | MasterField1
------------------------------------------
1 | one one one
------------------------------------------
2 | two two two
------------------------------------------
3 | three three three
------------------------------------------
4 | four four four
GageTable:
GageID | GageName | MasterID
----------------------------------------------------
1 | gage01 | 1
----------------------------------------------------
2 | gage12 | 1
----------------------------------------------------
3 | gage02 | 2
----------------------------------------------------
4 | gage03 | 3
----------------------------------------------------
5 | gage22 | 2
----------------------------------------------------
6 | gage04 | 4
----------------------------------------------------
7 | gage42 | 4
----------------------------------------------------
8 | gage45 | 4
MaterialTable:
MaterialID | MaterialName | MasterID
---------------------------------------------------------------
1 | Material01 | 1
---------------------------------------------------------------
2 | Material02 | 2
---------------------------------------------------------------
3 | Material03 | 3
---------------------------------------------------------------
4 | Material04 | 4
---------------------------------------------------------------
5 | Material033 | 3
---------------------------------------------------------------
6 | Material039 | 3
---------------------------------------------------------------
unionview (This is a View):
select `mastertable`.`MasterField1` AS `MasterField1`,'Gage' AS `TableName`,`gagetable`.`GageName` AS `Name`
from (`gagetable` join `mastertable`) where (`gagetable`.`MasterID` = `mastertable`.`MasterID`)
union
select `mastertable`.`MasterField1` AS `MasterField1`,'Material' AS `TableName`,`materialtable`.`MaterialName` AS `Name`
from (`mastertable` join `materialtable`) where (`materialtable`.`MasterID` = `mastertable`.`MasterID`)
order by `MasterField1`,'TableName',`Name`
The unionview yields the results below (which can be used in Report Builder):
MasterField1 | TableName | Name(which is GageName or MaterialName depending on table)
--------------------------------------------------------
four four four | Gage | gage04
--------------------------------------------------------
four four four | Gage | gage42
--------------------------------------------------------
four four four | Gage | gage45
--------------------------------------------------------
four four four | Material | Material04
--------------------------------------------------------
one one one | Gage | gage01
--------------------------------------------------------
one one one | Gage | gage12
--------------------------------------------------------
one one one | Material | Material01
--------------------------------------------------------
three three three | Gage | gage03
--------------------------------------------------------
three three three | Material | Material03
--------------------------------------------------------
three three three | Material | Material033
--------------------------------------------------------
three three three | Material | Material039
--------------------------------------------------------
two two two | Gage | gage02
--------------------------------------------------------
two two two | Gage | gage22
--------------------------------------------------------
two two two | Material | Material02
Hopefully this helps.
|