Search Postgresql Archives

Re: Combining two queries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux