Re: Combining two queries

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Combining two queries
Date: 2014-12-18 21:29:52
Message-ID: 1418938192282-5831391.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Robert DiFalco wrote
> For 2 arbitrary ids, I need a query to get two pieced of data:
> * Are the two users friends?

This seems easy...ROW(u_id, f_id) = ROW(n1, n2)

> * How many friends do the two users have in common.

SELECT f_id FROM [...] WHERE u_id = n1
INTERSECT
SELECT f_id FROM [...] WHERE u_id = n2

Put those into WITH/CTE and use the main query to combine them in whatever
way seems appropriate.

David J.

--
View this message in context: http://postgresql.nabble.com/Combining-two-queries-tp5831378p5831391.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Patrick Krecker 2014-12-18 21:31:23 Re: Combining two queries
Previous Message Robert DiFalco 2014-12-18 20:10:12 Combining two queries