UNION query question

1. LeeAnnie Guest

## UNION query question

I need to combine three-four queries into one query. Can I use UNION to do this?<BR><BR>For example:<BR><BR>SELECT colOne, colTwo, colThree<BR>FROM fruit<BR>WHERE colFour = &#039;Apples&#039;<BR>UNION<BR>SELECT colOne, colTwo, colThree<BR>FROM veggies<BR>WHERE colFour = &#039;Tomatoes&#039;<BR>UNION<BR>SELECT colOne, colTwo, colThree<BR>FROM grains<BR>WHERE colFour = &#039;Wheat&#039;;<BR><BR>Obviously, the query that I want to do is much more complex than this... I am just looking for the most efficient query. My current query looks something like this (it takes FOREVER to run):<BR><BR>SELECT colOne, colTwo, colThree<BR>FROM food, fruit, veggies, grains<BR>WHERE (colFour = &#039;Apples&#039;<BR>OR colFour = &#039;Tomatoes&#039;<BR>OR colFour = &#039;Wheat&#039;)<BR>AND fruit.colOne = food.colOne<BR>AND veggies.colOne = food.colOne<BR>AND grains.colOne = food.colOne;<BR><BR>Again, these queries are just examples, so they are not really "accurate". I just wanted to find out if the reserved word UNION can be used within a query more than one time. <BR><BR>Also, if anyone knows of a good resource that can tell me the "efficiency" that different types of queries have, that would definitely be awesome!<BR><BR>Thanks in advance!

2. Senior Member
Join Date
Dec 1969
Posts
1,849

## Union and join

The union statement, as you probably already know, will just add records to your recordset, the join will add attributes to your records... eg,<BR>table 1:<BR>field1<BR>field2<BR>field3<BR><BR>Table2<BR> field2-1<BR>field2-2<BR>field2-3<BR><BR>you can use a union<BR>Select table1.field1 from table 1<BR>union all<BR>select table2.field2-1 from table2<BR><BR>which will return one column with the records from both tables, or you can use a join<BR><BR>select table1.field1, table2.field2-1 from table1,table2<BR><BR>This will create two columns with every possible combination of table1 and table2...<BR><BR>-- Whol

3. LeeAnnie Guest

## RE: Union and join

I know that...<BR><BR>I need to know if I can use a UNION for three or more tables. Thought I was clear on that. Sorry....

4. Senior Member
Join Date
Dec 1969
Posts
1,849

## I believe so...

I believe you can, you just have to make sure each query has the same number of arguments...<BR><BR>-- Whol

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•