Re: [OT] SQL-question
[prev]
[thread]
[next]
[Date index for 2005/03/15]
SELECT p.id as this_person, is AS partner_id FROM Relationships r join
persons p on r.of =3D p.id
On Tue, 15 Mar 2005 17:23:09 +0100, Andreas Fromm
<Andreas.Fromm@xxxxxx.xxxxxxxxxxxx.xx> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>=20
> .--- .- -- . ... 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 =3D ?
> |
> 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
>=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.
>=20
>=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 following
> | 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-----
>=20
--=20
.--- .- -- . ... -.-- --- ---