Query help

RainX

Registered User.
Local time
Today, 07:11
Joined
Sep 22, 2006
Messages
89
Hi all,

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

I have 2 Queries

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

Code:
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
 

Attachments

  • untitled1.JPG
    untitled1.JPG
    43 KB · Views: 114
Hello:

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

Regards

Mark
 
thanks mark. I'll look into unions.
Its been awhile.
 
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:

Code:
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
;
 

Users who are viewing this thread

Back
Top Bottom