UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

> How to perform a SQL query that 'joins' two result sets instead of UNIONing them?    
 
   
Davidd31415
post Jul 12 2009, 11:34 AM
Post #1

UtterAccess Enthusiast
Posts: 69



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.
Go to the top of the page
 
+

Posts in this topic


Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 18th June 2013 - 02:55 AM