pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedNeed help in composing PostgreSQL query
2+ messages / 2 participants
[nested] [flat]
* Need help in composing PostgreSQL query
@ 2001-09-04 06:23 Vladimir V. Zolotych <gsmith@eurocom.od.ua>
2001-09-04 07:53 ` Re: Need help in composing PostgreSQL query Oliver Elphick <olly@lfix.co.uk>
0 siblings, 1 reply; 2+ messages in thread
From: Vladimir V. Zolotych @ 2001-09-04 06:23 UTC (permalink / raw)
To: pgsql-sql
Hi
Please help me compose the query in PostgreSQL.
Using PostgreSQL 7.1.2.
Suppose relations A and B have columns:
{X1, X2, ..., Xm, Y1, Y2, ..., Yn}
and
{Y1, Y2, ..., Yn}
Attributes Y1, Y2, ..., Yn are common for both relations
and have the same type in both.
How can I define in PostgreSQL the query producing
relation with columns X1,X2,...,Xm containing all those tuples
satisfying conditon: relation A contains tupple
{x1,x2,...xm,y1,y2,...,yn}
for _each_ tupple
{y1,y2,...,yn}
in relation B ? Where x1 denotes particular value of
colum X1 etc.
For example: consider two tables DEND and DOR.
DEND DOR
s | p p
----+---- ----
s1 | p1 p1
s1 | p2 p2
s1 | p3 p3
s1 | p4 p4
s1 | p5 p5
s1 | p6 p5
s2 | p1 (6 rows)
s2 | p2
s3 | p2
s4 | p2
s4 | p4
s4 | p5
(12 rows)
For such tables our desired query should return:
s
----
s1
Thanks in advance.
--
Vladimir Zolotych gsmith@eurocom.od.ua
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Need help in composing PostgreSQL query
2001-09-04 06:23 Need help in composing PostgreSQL query Vladimir V. Zolotych <gsmith@eurocom.od.ua>
@ 2001-09-04 07:53 ` Oliver Elphick <olly@lfix.co.uk>
0 siblings, 0 replies; 2+ messages in thread
From: Oliver Elphick @ 2001-09-04 07:53 UTC (permalink / raw)
To: Vladimir V. Zolotych <gsmith@eurocom.od.ua>; +Cc: pgsql-sql
"Vladimir V. Zolotych" wrote:
>Hi
>
>Please help me compose the query in PostgreSQL.
>Using PostgreSQL 7.1.2.
>
>Suppose relations A and B have columns:
> {X1, X2, ..., Xm, Y1, Y2, ..., Yn}
>and
> {Y1, Y2, ..., Yn}
>Attributes Y1, Y2, ..., Yn are common for both relations
>and have the same type in both.
>
>How can I define in PostgreSQL the query producing
>relation with columns X1,X2,...,Xm containing all those tuples
>satisfying conditon: relation A contains tupple
> {x1,x2,...xm,y1,y2,...,yn}
>for _each_ tupple
> {y1,y2,...,yn}
>in relation B ? Where x1 denotes particular value of
>colum X1 etc.
You seem to be talking about a natural join:
SELECT *
FROM a,b
WHERE a.y1 = b.y1 AND a.y2 = b.y2 AND ... AND a.yn = b.yn;
>For example: consider two tables DEND and DOR.
>
>DEND DOR
>
> s | p p
>----+---- ----
> s1 | p1 p1
> s1 | p2 p2
> s1 | p3 p3
> s1 | p4 p4
> s1 | p5 p5
> s1 | p6 p5
> s2 | p1 (6 rows)
> s2 | p2
> s3 | p2
> s4 | p2
> s4 | p4
> s4 | p5
>(12 rows)
>
>For such tables our desired query should return:
>
> s
>----
> s1
SELECT DOR.s
FROM DEND,DOR
WHERE DOR.p = DEND.p;
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"If any of you lack wisdom, let him ask of God, who
gives to all men generously and without reproach, and
it will be given to him." James 1:5
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2001-09-04 07:53 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-09-04 06:23 Need help in composing PostgreSQL query Vladimir V. Zolotych <gsmith@eurocom.od.ua>
2001-09-04 07:53 ` Oliver Elphick <olly@lfix.co.uk>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox