473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Inclusive AND with an exclusive OR search

Hi,

Lets say I have a many to many cross-referenced table

b | t
-----
A | 1
A | 2
A | 3
A | 4
B | 1
B | 2
C | 3
C | 4
D | 2
D | 3
E | 1
E | 3
E | 4

If I want to get all cases of b which include 1, 3 and 4 I will use:

SELECT b FROM t AS t1, t AS t2, t AS t3 WHERE t1.b = t2.b AND t3.b =
t1.b AND t2.b = t3.b AND t2.a = 2 AND t1.a = 1 AND t3.a = 3

This will return A and E.

This is an AND search. How do I change this to include exclusive terms.
For example if I want any result that has 2 AND 3 but NOT 1 OR 4. Note
that the exclusive term is an OR not an AND.

This would return D

Many thanks!

Sep 14 '05 #1
2 3788
jg*****@gmail.com wrote:
SELECT b FROM t AS t1, t AS t2, t AS t3 WHERE t1.b = t2.b AND t3.b =
t1.b AND t2.b = t3.b AND t2.a = 2 AND t1.a = 1 AND t3.a = 3

This is an AND search. How do I change this to include exclusive terms.
For example if I want any result that has 2 AND 3 but NOT 1 OR 4. Note
that the exclusive term is an OR not an AND.


In boolean algebra, BUT means the same thing as AND. ;-)

WHERE t2.a = 2 AND t1.a = 1 AND t3.a = 3
AND NOT (t1.a = 1 OR t2.a = 4)

Also, I note that your join conditions are redundant. If t1.b = t2.b
and t1.b = t3.b, then t2.b = t3.b must be true, and it is not necessary
to express the condition. Though the MySQL optimizer may be able to
factor it out.

Regards,
Bill K.
Sep 14 '05 #2
Hi,

Many thanks for your suggestions. I have tried the AND NOT, and it just
doesn't work. The returned query always includes the included terms,
regardless of the exclusion.

Sep 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Paul Munly | last post by:
Hi, I'm attempting to get a Swing application to go into Exclusive Fullscreen mode and am curious if there's something that I need to do prior to attempting to grab the fullscreen window. The...
0
by: krystoffff | last post by:
Hi I have the following database under MySQL 4.1 : //////////////////////////////////////////////////// # Table structure for table `affiliate_lockout` # CREATE TABLE `affiliate_lockout` (...
3
by: Matthias Heuer | last post by:
Hi, we try to deploy a quite heavyweight .NET (C#) Rich Client App (2 Tier) via IIS Server Zero Touch, but it requires about 4-6 times more Processor Time and is thus 3-4 times slower than if...
3
by: Uwe C. Schroeder | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi. I have the following little stored proc: CREATE OR REPLACE FUNCTION public.ib_nextval(varchar) RETURNS varchar AS 'DECLARE
0
by: David Mediavilla | last post by:
I am trying to check a SOAP signature with WSE 1.0 SP1, but with a certain transform I only get an "Unknown tranform" exception. The SOAP signature is like this: <ds:Signature>...
1
by: Rohit Raghuwanshi | last post by:
Hello all, we are running a delphi application with DB2 V8.01 which is causing deadlocks when rows are being inserted into a table. Attaching the Event Monitor Log (DEADLOCKS WITH DETAILS) here....
1
by: University of Toronto | last post by:
Hi gang, Hopefully someone can help us out. In short - Access 2002, db split into a front end and back end. It appears that our backend db is locked. Our form bound to one table won't allow...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
3
by: Arun Srinivasan | last post by:
Please correct me if I am wrong 1. no 2 processes can have exclusive lock on same object (by object, same row or same table) 2. on deadlock incident between 2 processes only one of them will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.