473,508 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Relationship between two members - HELP!

3 New Member
Hi all, What I'm trying to do and having a lot of trouble with is pulling how one user is related to another user from my database. I'll explain...

The table (relationships) looks like this:
ID
type: int

RELID1
type: int, is the user id that initiated the relationship request.

RELID2
type: int, is the user id of the second person in the relationship.

Story
type: varchar(255), quick blerb on how they are related.

Type
type: int, a number 1-20 based on the relationship they have

Status
type: int, 1 = confirmed by second person, 0 = not confirmed

What i'd like to have pulled is a list of the people that person (for example: 70) is related to. I am having the two following problems:
1. unqid of "70" could be in RELID1 or RELID2 as they could have initiated the request or been the second person.
2. I don't want to display them selves in their own relationship listing

Example Data:
ID
1
2
3
4

RELID1
25
15
70
12

RELID2
54
70
13
8

Story
Met on the east coast
Met at walmart
Met walking
Met outside

Type
14
11
3
8

Status
1
1
1
1

Example Output:
Again assuming the current user is "70", the sql should pull: 15, 13.. but i'd like to pull their names from another table called "Users" where "15" and "13" are the UnqID's in a column called "ID".
So:
15 = Bob Smith
13 = Jane DOe

[b]What I've Tried:[b]
Expand|Select|Wrap|Line Numbers
  1. SELECT RELID1, RELID2, FirstName, LastName
  2. FROM Relationship
  3. INNER JOIN ReMembers
  4. ON Relationship.RELID1 = ReMembers.AccountID
  5. WHERE RELID1 = 70 OR RELID2 = 70
  6.  
This works, however, this only works for RELID1 and not RELID2 column. Moreover, this repeats the data for some reason.


If you have any more questions, or something isn't clear please let me know!

THANKS!

~ PhIve ~
Dec 9 '06 #1
1 1241
almaz
168 Recognized Expert New Member
[b]What I've Tried:[b]
...
This works, however, this only works for RELID1 and not RELID2 column. Moreover, this repeats the data for some reason.
Your query is correct, you just don't select the second member's name:
Expand|Select|Wrap|Line Numbers
  1. SELECT RELID1, RELID2, R1.FirstName, R1.LastName, R2.FirstName, R2.LastName
  2. FROM Relationship
  3. INNER JOIN ReMembers R1 ON Relationship.RELID1 = R1.AccountID
  4. INNER JOIN ReMembers R2 ON Relationship.RELID2 = R2.AccountID
  5. WHERE RELID1 = 70 OR RELID2 = 70
  6.  
Dec 11 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2741
by: Alcyone Oliveira | last post by:
------=_NextPart_000_000D_01C36572.F6480CE0 Content-Type: multipart/alternative; boundary="----=_NextPart_001_000E_01C36572.F6480CE0" ------=_NextPart_001_000E_01C36572.F6480CE0 Content-Type:...
28
2184
by: Jeff Lanfield | last post by:
Suppose I have users that can belong to organizations. Organizations are arranged in a tree. Each organization has only one parent organization but a user maybe a member of multiple organizations....
2
1495
by: Ken Loh | last post by:
Hi All, I'd like to develop something which has a concept like the folders-and-files in your PC. A folder can have subfolders and/or files. The subfolders themselves have the same...
2
1971
by: William Bradley | last post by:
Some help with relationships would be appreciated. I have read up on them but am still a bit vague ... The tables are as follows: 1. Main table -- this holds information about a product we...
3
1604
by: Mason | last post by:
I have a table consisting of people and their attributes. I would like to create a relationship matrix table that records the relationships between the people. So the two tables would look...
2
2346
by: Sukkel | last post by:
When I define relations in the Backend of my Database, everything works fine. I get these funny lines (with 1 and "OO") between the fields of the different table that indicate a one to many...
5
2379
by: BrianDP | last post by:
This is a strange one-- I have an Access 2K database with a split front end/back end. There are two tables in the back end - RFile and RLine. There is a one to many relationship from...
1
2688
by: smook | last post by:
Hi all I have a SQL Server 2000 database that I converted from an access database. The interface is still existing in Access... Basically I have 2 tables in a many to many relationship -...
5
2991
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I am actually a VB.Net guy, but I have worked somewhat with C++ and C#. I just want to ask about the relationship between Abstract Classes and Interfaces. My first question is if...
0
7227
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
7127
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7054
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
7501
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...
0
4713
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...
0
3204
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...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
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 ...
0
424
bsmnconsultancy
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...

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.