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

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> 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
 
+
niesz
post Jul 12 2009, 12:14 PM
Post #2

Utter A-fishin'-ado
Posts: 17,723
From: Cincinnati, Ohio, USA . . . ><((((°>



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

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

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 26th May 2013 - 04:08 AM