473,395 Members | 1,474 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,395 software developers and data experts.

selecting non mutual results

hah well I'm here again, guess I need more practice to do this all properly!

I have a table, such as this:

friends

+--------+----------+
| userid | friendid |
+--------+----------+
| 2 | 7 |
| 2 | 3 |
| 2 | 6 |
| 2 | 8 |
| 2 | 9 |
| 2 | 34 |
| 7 | 2 |
| 34 | 2 |
| 9 | 2 |
| 2 | 47 |
+--------+----------+

and Bill K kindly helped with the code to fine opposite column matches (2
and 7, 7 and 2 for example) but now I want to return the results for a
specific user excluding these opposite column matches. How can I do this?

Thank you all again!
Jul 23 '05 #1
2 1107
So you want all the pairs for a given user that don't have reciprocal
pairs? Is that right? For user 2, then, you'd want (2,3), (2,6), (2,8),
and (2,47)?

SELECT t1.*
FROM friends AS t1
LEFT JOIN friends AS t2
ON t1.userid = t2.friendid
AND t1.friendid = t2.userid
WHERE t1.userid = 2
AND t2.userid IS NULL

For pairs that -do- have reciprocals, you could switch the WHERE clause
to "t2.userid IS NOT NULL".

Jul 23 '05 #2

"cainlevy" <go***********@cainlevy.net> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
So you want all the pairs for a given user that don't have reciprocal
pairs? Is that right? For user 2, then, you'd want (2,3), (2,6), (2,8),
and (2,47)?

SELECT t1.*
FROM friends AS t1
LEFT JOIN friends AS t2
ON t1.userid = t2.friendid
AND t1.friendid = t2.userid
WHERE t1.userid = 2
AND t2.userid IS NULL

For pairs that -do- have reciprocals, you could switch the WHERE clause
to "t2.userid IS NOT NULL".


That's great, thanks! It's shocking how close the solution was to what I
had. Must need more practice :)
Jul 23 '05 #3

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

Similar topics

0
by: Morten Gulbrandsen | last post by:
Hello Programmers, Thank you for the kind advice, I have another small problem with MySQL I'd like to investigate, All I get is this:=20 ERROR 1005 at line 47:=20 Can't create table...
0
by: Morten Gulbrandsen | last post by:
mysql> USE company; Database changed mysql> mysql> DROP TABLE IF EXISTS EMPLOYEE; -------------- DROP TABLE IF EXISTS EMPLOYEE -------------- Query OK, 0 rows affected (0.00 sec)
5
by: clusardi2k | last post by:
Hello, I have a assignment just thrown onto my desk. What is the easiest way to solve it? Below is a brief description of the task. There are multible programs which use the same library...
0
by: Support | last post by:
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <head>...
2
by: Phillip Parr | last post by:
Hey all, I'm probably just having a lax moment but I can't quite figure this out. Say I have a table such as this: friends user friend 1 2 1 3 2 4 2 1
2
by: icoba | last post by:
I have the following code: A.py ==== from B import B class R: def __str__(self): return "hello world"
0
by: Paul | last post by:
I have found a web service that provides stock quotes on a twenty minute delay for free. Does anyone know of a web service that provides the mutual fund prices, hopefully for the same price? Thanks.
3
by: joshsackett | last post by:
I am having a problem with indexes on specific tables. For some reason a query that runs against a view is not selecting the correct index on a table. I run the same query against the table...
1
by: illegal.prime | last post by:
So I have a container of objects that I don't want to iterate across when I'm modifying it. I.E. I lock on adds and deletes to the container - so that my traversals of it don't result in...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.