View Full Version : Query help


RainX
01-19-2007, 09:50 AM
Hi all,

My minds a running a blank so please bear with me.

I have 2 Queries

SELECT ElectionResultsCandOnly2002.Year, ElectionResultsCandOnly2002.Twp, ElectionResultsCandOnly2002.[Party Abbreviation], ElectionResultsCandOnly2002.[Candidate Name], ElectionResultsCandOnly2002.VoteNum
FROM ElectionResultsCandOnly2002
WHERE (((ElectionResultsCandOnly2002.Twp)=701));

SELECT ElectionResultsGov1998.Year, ElectionResultsGov1998.Twp, ElectionResultsGov1998.CAND_PARTY, ElectionResultsGov1998.CANDNAME, ElectionResultsGov1998.VOTES
FROM ElectionResultsGov1998
WHERE (((ElectionResultsGov1998.Twp)=701));

You can look at the output in the attached image.

What id like to do is make a query that combines both by
ElectionResultsGov1998.Twp and
ElectionResultsCandOnly2002.Twp These two are like id numbers there are more but i just gave a sample of one.

What i'd like the results to show are 4 rows (cause the maximum in one of the queries is 4) with the first query on the first 5 columns and the second query on the next 5 columns.

Whenever i try to combine them i get weird results like 16 rows so i dont know what im doing wrong.


Thanks in advance

mhartman
01-19-2007, 10:27 AM
Hello:

You would need to construct a UNION query to do this.

Regards

Mark

RainX
01-19-2007, 12:21 PM
thanks mark. I'll look into unions.
Its been awhile.

Moniker
01-19-2007, 03:33 PM
The union needs all the fields in both tables to have the same structure. To get the names lined up, do aliasing. It will look like this:

SELECT
Table1.Field1
,Table1.Field2
,Table1.Field3
FROM
Table1

UNION SELECT
Table2.Field10 AS Field1
,Table2.Field20 AS Field2
,Table2.Field30 AS Field3
FROM
Table2
;