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! 2 1126
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".
"cainlevy" <go***********@ cainlevy.net> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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 :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 '.\company\#sql-40c_4.frm' (errno: 150)
|
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)
|
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 routine
which is an interface to what I'll call a service program.
|
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>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
|
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
| |
by: icoba |
last post by:
I have the following code:
A.py
====
from B import B
class R:
def __str__(self):
return "hello world"
|
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.
|
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 directly and it looks
fine. Can anyone give me some insight? Thanks.
PRODUCTION1:
CREATE TABLE MyTest1 (ID INT IDENTITY(1,1), COLUMN1 CHAR(10), COLUMN2
CHAR(10))
CREATE CLUSTERED INDEX IDX_MyTest1 ON MyTest1 ON (ID)
CREATE NONCLUSTERED INDEX...
|
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 concurrency
issues.
However, what do I need to do to allow multiple threads to traverse
the container without synchronization/mutual-exclusion - but ensure
that synchronization/mutual-exclusion is there when the container is
trying to be both changed...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |