vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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: 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.thui sploeg 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.thui sploeg ) 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.uitp loeg ) 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.uitp loeg ) 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.thui sploeg ) AS groep FROM tbl_wk_wedstrijd INNER JOIN tbl_wk_stadion ON tbl_wk_wedstrijd.stadionid=tbl_wk_stadion.stadioni d INNER JOIN tbl_wk_typewedstrijd ON tbl_wk_wedstrijd.typewedstrijdid=tbl_wk_typewedstr ijd.typewedstrijdid; Thnx, Arjan __________________________________________________ _______________ Vind alles terug op je PC: MSN Search Toolbar http://toolbar.msn.nl/ ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend |
| ||||
| 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.thui sploeg > 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.thui sploeg > 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.thui sploeg > ) 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.uitp loeg > ) 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.uitp loeg > ) 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.thui sploeg > ) AS groep > > FROM tbl_wk_wedstrijd INNER JOIN tbl_wk_stadion ON > tbl_wk_wedstrijd.stadionid=tbl_wk_stadion.stadioni d > INNER JOIN tbl_wk_typewedstrijd ON > tbl_wk_wedstrijd.typewedstrijdid=tbl_wk_typewedstr ijd.typewedstrijdid; ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster |