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/[EMAIL PROTECTED]