Search Postgresql Archives

Re: ERROR: more than one row returned by a subquery used

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

 



On Wed, 3 May 2006, Arjan Vroege wrote:

> Hello,
>
> I have the following Query with Subqueries.
> This query gives the error : ERROR: more than one row returned by a subquery
> used as an expression. Is there a solution to solve this problem:

Scalar subqueries (like the ones in your select list) can't return more
than one row since it'd be effectively random which row's value came out
(and if the values are known to have to be the same you can use distinct
in the subquery).


Given a subquery like this from the query...
>         (SELECT tbl_wk_land.landnaam FROM tbl_wk_land
>             INNER JOIN tbl_wk_landgroep ON
> tbl_wk_land.landid=tbl_wk_landgroep.landid
>             INNER JOIN tbl_wk_wedstrijd ON
> tbl_wk_landgroep.landgroepid=tbl_wk_wedstrijd.thuisploeg
>             WHERE tbl_wk_land.landid=tbl_wk_landgroep.landid) AS thuisploeg,

Unless I'm missing something in the table naming, this isn't going to be
associated with the particular outer row that the select list is being run
for and the where clause seems redundant with the join clause. Is that the
intent?

>
> SELECT  tbl_wk_wedstrijd.wedstrijdid,
>         tbl_wk_wedstrijd.thuisploeg AS thuisploegid,
>         tbl_wk_wedstrijd.uitploeg AS uitploegid,
>         (SELECT tbl_wk_land.landnaam FROM tbl_wk_land
>             INNER JOIN tbl_wk_landgroep ON
> tbl_wk_land.landid=tbl_wk_landgroep.landid
>             INNER JOIN tbl_wk_wedstrijd ON
> tbl_wk_landgroep.landgroepid=tbl_wk_wedstrijd.thuisploeg
>             WHERE tbl_wk_land.landid=tbl_wk_landgroep.landid) AS thuisploeg,
>         (SELECT tbl_wk_land.landvlag FROM tbl_wk_land
>             INNER JOIN tbl_wk_landgroep ON
> tbl_wk_land.landid=tbl_wk_landgroep.landid
>             INNER JOIN tbl_wk_wedstrijd ON
> tbl_wk_landgroep.landgroepid=tbl_wk_wedstrijd.thuisploeg
>             ) AS thuisploegvlag,
>         (SELECT tbl_wk_land.landnaam FROM tbl_wk_land
>             INNER JOIN tbl_wk_landgroep ON
> tbl_wk_land.landid=tbl_wk_landgroep.landid
>             INNER JOIN tbl_wk_wedstrijd ON
> tbl_wk_landgroep.landgroepid=tbl_wk_wedstrijd.uitploeg
>             ) AS uitploeg,
>         (SELECT tbl_wk_land.landvlag FROM tbl_wk_land
>             INNER JOIN tbl_wk_landgroep ON
> tbl_wk_land.landid=tbl_wk_landgroep.landid
>             INNER JOIN tbl_wk_wedstrijd ON
> tbl_wk_landgroep.landgroepid=tbl_wk_wedstrijd.uitploeg
>             ) AS uitploegvlag,
>         tbl_wk_stadion.stadionplaats,
>         tbl_wk_stadion.stadionnaam,
>         tbl_wk_stadion.stadiongrootte,
>         tbl_wk_stadion.stadionplaatje,
>         tbl_wk_typewedstrijd.typewedstrijdnaam,
>         tbl_wk_wedstrijd.datumentijd,
>         tbl_wk_wedstrijd.omschrijving,
>         tbl_wk_wedstrijd.uitslagthuis,
>         tbl_wk_wedstrijd.uitslaguit,
>         (SELECT tbl_wk_groep.groepnaam FROM tbl_wk_groep
>             INNER JOIN tbl_wk_landgroep ON
> tbl_wk_groep.groepid=tbl_wk_landgroep.groepid
>             INNER JOIN tbl_wk_wedstrijd ON
> tbl_wk_landgroep.landgroepid=tbl_wk_wedstrijd.thuisploeg
>             ) AS groep
>
>         FROM tbl_wk_wedstrijd   INNER JOIN tbl_wk_stadion ON
> tbl_wk_wedstrijd.stadionid=tbl_wk_stadion.stadionid
>                                 INNER JOIN tbl_wk_typewedstrijd ON
> tbl_wk_wedstrijd.typewedstrijdid=tbl_wk_typewedstrijd.typewedstrijdid;


[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