Re: [OT] SQL-question

[prev] [thread] [next] [Date index for 2005/03/15]

From: Andreas Fromm
Subject: Re: [OT] SQL-question
Date: 16:23 on 15 Mar 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



.--- .- -- . ... wrote:
| There's something I must be missing in your question because as its
| stated it seems pretty straight forward....
|
| select of as partner_id from relationships where is = ?
|
Thats one part, but what if I am asking for the partner of someone who
itself is registred as the 'of'-person. If the recor in Relationships is

1 is partner of 2

and then i need to find the partner of 2, I would need:
SELECT is AS partner_id FROM Relationships WHERE of = ?

My problem is how to write both querys as one.


| <Andreas.Fromm@xxxxxx.xxxxxxxxxxxx.xx> wrote:
|
| Hi,
|
| i know I'm slightly off topic, but I don't know where else to ask. I
| have a little SQL-question abaut a linking table. I have the following
| tables:
|
| CREATE TABLE Person (
| ~  id serial PRIMARY KEY
| ~  name text,
| ~  ...
| );
|
| CREATE TABLE Relations (
| ~  is integer REFERENCES Person,
| ~  rel char(7) CHECK ( rel == 'partner' OR ... ),
| ~  of integer REFERENCES Person,
| ~  CONSTRAINT Relations_pkey PRIMARY KEY ( is, rel )
| );
|
| Now I would like to make a query to the Relations table asking if some
| 'person' is the partner of another, and get the id of the partner. How
| would the SQL look like if I just have the row (1 is partner of 2) and
| not the row (2 is partner of 1) in the Relations table?
|
| Thanks in advance.
|

- --
Grüsse,

Andreas Fromm

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCNwvtUmBtSMq5cGURAhMCAJ98M+aFzPSGt8c5Zw0q4pfCDn4WggCgiv8Q
6wxjSZdKd1tAacIxLJlsWSk=
=Yuk1
-----END PGP SIGNATURE-----

[OT] SQL-question
Andreas Fromm 13:49 on 15 Mar 2005

Re: [OT] SQL-question
Andreas Fromm 16:23 on 15 Mar 2005

Re: [OT] SQL-question
Dave Cross 16:52 on 15 Mar 2005

Re: [OT] SQL-question
Kingsley Kerce 16:55 on 15 Mar 2005

Re: [OT] SQL-question
.--- .- -- . ... 16:58 on 15 Mar 2005

Generated at 21:05 on 16 Mar 2005 by mariachi v0.52