|
|||||||||||
|
Re: [GENERAL] "Concatenate" two queries - how?
From: Stanislav Raskin <sr(at)brainswell.de>
Date: Wed Oct 24 2007 - 09:27:23 EDT
http://www.postgresql.org/docs/8.2/interactive/sql-select.html#SQL-UNION
-----Ursprüngliche Nachricht-----
Hi there, I have two queries, which I would like to bring together to form one result. The first query is a simple SELECT on a table of national statistics. SELECT COALESCE(c.name, ''''), year_start AS year, value FROM fish_catch AS d LEFT JOIN countries AS c ON c.id = id_country WHERE The second query is an aggregation-on-the-fly of these national statistics to its regions. The result is for example not "Germany, France, Algeria, ...", but "Europe, Africa, ..." SELECT COALESCE(r.name, ''''), year_start AS year, SUM(value) AS value FROM life_expect AS d LEFT JOIN countries_view AS c ON c.id = id_country RIGHT JOIN regions AS r ON r.id = c.reg_id WHERE Now, I want to enable queries which display national as well as regional values. I could probably work with independent queries, but I think it would be "cleaner" and more efficient to get everything into a single query. Can someone give me a hint how this would work? Thanks a lot! Stef
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq Received on Wed Oct 24 09:32:34 2007 This archive was generated by hypermail 2.1.8 : Mon Jun 16 2008 - 18:46:57 EDT |
||||||||||
|
|||||||||||