Re: [OT] SQL-question

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

From: Kingsley Kerce
Subject: Re: [OT] SQL-question
Date: 16:55 on 15 Mar 2005
Andreas Fromm writes:
 > -----BEGIN PGP SIGNED MESSAGE-----
 > Hash: SHA1
 >=20
 >=20
 >=20
 > .--- .- -- . ... wrote:
 > | There's something I must be missing in your question because as it=
s
 > | stated it seems pretty straight forward....
 > |
 > | select of as partner_id from relationships where is =3D ?
 > |
 > Thats one part, but what if I am asking for the partner of someone w=
ho
 > itself is registred as the 'of'-person. If the recor in Relationship=
s is
 >=20
 > 1 is partner of 2
 >=20
 > and then i need to find the partner of 2, I would need:
 > SELECT is AS partner_id FROM Relationships WHERE of =3D ?
 >=20
 > My problem is how to write both querys as one.

Try SQL's UNION, as in the following query to find the partner of 2:

SELECT of FROM relationships WHERE is =3D 2
UNION
SELECT is FROM relationships WHERE of =3D 2

Kings

 >=20
 > | <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 follo=
wing
 > | tables:
 > |
 > | CREATE TABLE Person (
 > | ~  id serial PRIMARY KEY
 > | ~  name text,
 > | ~  ...
 > | );
 > |
 > | CREATE TABLE Relations (
 > | ~  is integer REFERENCES Person,
 > | ~  rel char(7) CHECK ( rel =3D=3D '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.
 > |
 >=20
 > - --
 > Gr=FCsse,
 >=20
 > Andreas Fromm
 >=20
 > -----BEGIN PGP SIGNATURE-----
 > Version: GnuPG v1.2.6 (GNU/Linux)
 > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
 >=20
 > iD8DBQFCNwvtUmBtSMq5cGURAhMCAJ98M+aFzPSGt8c5Zw0q4pfCDn4WggCgiv8Q
 > 6wxjSZdKd1tAacIxLJlsWSk=3D
 > =3DYuk1
 > -----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