View Full Version : How do I avoid the union query sucking up the individuality of my tables


CarlaKingery
05-31-2002, 12:29 PM
Oh help, I just need one piece and my database would be perfect...well almost.

I created a union query with the following syntax:

SELECT [Parent Company Name], [IOU], [Count], [SumOfCount]
FROM [Utilparentcount]

UNION ALL SELECT [Parent Company Name], [NonIOU], [Count], [SumOfCount]
FROM [UtilparcountNonIOU]

UNION ALL SELECT [Parent Company Name], [LDC], [Count], [SumOfCount]
FROM [UtilparcountLDC]

It worked beutifully, except I need to have a separate field that shows from what table each record originated. This is important because it tells me what type of utility each record is IOU, NonIOU, or LDC. Any suggestions?

C

llkhoutx
05-31-2002, 12:53 PM
SELECT [Parent Company Name], [IOU], [Count], [SumOfCount], "Table A" AS Source
FROM [Utilparentcount]

UNION ALL SELECT [Parent Company Name], [NonIOU], [Count], [SumOfCount], "Table B" AS Source
FROM [UtilparcountNonIOU]

UNION ALL SELECT [Parent Company Name], [LDC], [Count], [SumOfCount], "Table C" AS Source
FROM [UtilparcountLDC]

CarlaKingery
06-03-2002, 04:40 AM
Thanks so much, Perfect!!

C

KKilfoil
06-03-2002, 09:08 AM
*** Normalization Alert! ****

Why have 3 different tables?

You should add a 'UtilityType' Field and store all data in one table. Then your queries and everything else gets much simpler.

Look up 'normalization' in this forum's search feature or Access help for more information on how and why your database should be normalized!