Hmmm..... Don't really get that query working. My SQL looks like this now:

SELECT
   id_country,
   year,
   value
FROM
  internet_users
NATURAL JOIN
  gdp
WHERE
   id_country = 8
ORDER BY
   year
LIMIT
   1

Ok, got it working with another proposed SQL SELECT. This is a solution (comes out of an PHP loop, so one could easily have more than 2 subselects). Thanks for the help to everyone!!

SELECT
        year0 AS common_year,
        v0.val0 AS v0_value,
        v1.val1 AS v1_value
FROM
        (
                SELECT
                        year AS year0,
                        value AS val0
                FROM
                gdp_capita
                WHERE
                        id_country = 672 AND
                        value IS NOT NULL
        ) AS v0,
        (
                SELECT
                        year AS year1,
                        value AS val1
                FROM
                agri_add_gdp
                WHERE
                        id_country = 672 AND
                        value IS NOT NULL
        ) AS v1
WHERE
        v1.year1 = v0.year0 AND
        v1.year1 = v1.year1
ORDER BY
        v0.year0
LIMIT
        1


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

              http://archives.postgresql.org/

Reply via email to