Full Version: How to perform a SQL query that 'joins' two result sets instead of UNIONing them?
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
Davidd31415
I have:

SELECT * FROM tables WHERE field1 LIKE 'term1' OR field1 LIKE 'term2'
UNION
SELECT * FROM tables WHERE field2 LIKE 'term1' or field2 LIKE 'term2'

What I would like is for these results to be 'joined' such that only matches between the two result sets are returned.

term1 and term2 may both be applicable to only field1, only field2, or both fields.

I guess another way to look at this would be that I want to do a clause like:

WHERE x AND y AND z (there are actually three fields)

but only if x, y, and z all return results. If one of them does not, it should not be included.

Any ideas how I can obtain the query I am after?

The only thing I can think of is to create three separate queries and then query those with JOINs.

Regards,

David

Edited by: Davidd31415 on Sun Jul 12 12:45:36 EDT 2009.
niesz
Please post your table structure with the real tablenames and fieldnames and a few lines of sample data, along with what you want returned and we'll see if we can assist further.

Using pseudonyms makes it difficult for us to know what you want.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.