List:General Discussion« Previous MessageNext Message »
From:Alvaro Cobo Date:August 18 2005 2:41pm
Subject:Re: Subquery returns more than 1 row (1242). Solved.
View as plain text  
Thanks Phillipe:

Perfect. It worked!!!. All solved with your help. And actually, the subquery
returns more than one row, and it inserts all the data I need under the
WHERE condition without any problem.

Thanks again and best regards,

Alvaro.

----- Original Message -----
From: "Philippe Poelvoorde" <philippe@stripped>
To: <mysql@stripped>
Sent: Thursday, August 18, 2005 1:59 AM
Subject: Re: Subquery returns more than 1 row (1242)


> Alvaro Cobo wrote:
> > Hi guys:
> >
> > I work with some grassroot communities, which we have to keep following
up. And we need to know how the population changes in the different years.
> >
> > What I figured out is to have two tables: one to have the name of the
organization, and the second which contains the changes in the time.
> >
> > To avoid people having to input the stored data each time (and just
update from the stored data), I am trying to create a query which inserts
(re-inserts) the primary key of the primary table into the Foreign Key field
of the secondary table, adding the current year, and then the user just have
to update the information and it has the year collected from a form
variable.
> >
> > The query is as follows:
> >
> > INSERT INTO tbl_secondary( FK_ORG, year )
> > VALUES (
> >     (SELECT PK_ORG
> >     FROM tbl_primary
> >     WHERE Province = 'Province1'), 2006
> >                 )
> >
> > It gives me the following error message: "1242. Subquery returns more
than 1 row"
> >
> > If I try to do the following query it works, but it is not useful for me
because we need to insert the data with its especific year (timestamp is not
useful as well):
> >
> > INSERT INTO tbl_secondary( FK_ORG )
> > (
> > SELECT PK_ORG
> > FROM tbl_primary
> > WHERE Province = 'Province1'
> > )
>
> What about :
> INSERT INTO  tbl_secondary( FK_ORG, year )
> SELECT PK_ORG, 2006
>      FROM tbl_primary
>      WHERE Province = 'Province1';
>
> (If you are sure the SELECT returns only one row, and that you have a
> UNIQUE index on (FK_ORG,Year). )
>
> --
> Philippe Poelvoorde
> COS Trading Ltd.
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
>

Thread
Subquery returns more than 1 row (1242)Alvaro Cobo18 Aug
  • Re: Subquery returns more than 1 row (1242)Philippe Poelvoorde18 Aug
  • Re: Subquery returns more than 1 row (1242). Solved.Alvaro Cobo18 Aug