Is it possible to combine these?

J

James Parham

I have two queries that work exactly the way I want them to. The difference
between the two is that one query looks for a value of 1 in FloatTable.Val,
using tAlarms_OFF_IS_OK in the criteria, while the other query looks for a
value of 0 in FloatTable.Val, using tAlarms_ON_IS_OK in its criteria:


SELECT FloatTable.DateAndTime, TagTable.TagName,
tAlarms_OFF_IS_OK.Description
FROM tAlarms_OFF_IS_OK INNER JOIN (TagTable INNER JOIN FloatTable ON
TagTable.TagIndex = FloatTable.TagIndex) ON tAlarms_OFF_IS_OK.Name =
TagTable.TagName
WHERE (((FloatTable.Val)=1));

SELECT FloatTable.DateAndTime, TagTable.TagName,
tAlarms_ON_IS_OK.Description
FROM tAlarms_ON_IS_OK INNER JOIN (TagTable INNER JOIN FloatTable ON
TagTable.TagIndex = FloatTable.TagIndex) ON tAlarms_ON_IS_OK.Name =
TagTable.TagName
WHERE (((FloatTable.Val)=0));


The problem I have is that using the above queries requires that I run two
separate queries and that I work with two separate result recordsets. What
I want to do is combine both queries into a single SQL statement that
returns one recordset. (Or if that isn't possible, modify the two queries
so they combine both recordset results into a single recordset.)


Anyone know how this might be accomplished?
 
A

Allen Browne

You can combine the results of 2 queries with a UNION

Assuming the fields are identical (as in your example), the SQL statement
is:
SELECT Query1.*
UNION ALL
SELECT Query2.*;
Access can't show UNION queries graphically, so you are in SQL View here.
 
J

James Parham

Sweet. That worked perfectly.

Thanks!




Allen Browne said:
You can combine the results of 2 queries with a UNION

Assuming the fields are identical (as in your example), the SQL statement
is:
SELECT Query1.*
UNION ALL
SELECT Query2.*;
Access can't show UNION queries graphically, so you are in SQL View here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top