-
Funny query problem
I have 2 tables, "tblJob" and "tblRegion".
tblJob tblRegion
====== M---1 =======
Job_PK Reg_PK
Reg_FK Reg_Name
Reg_Name
tblJob has a list of jobs and a foreign key pointing to the tblRegion which holds a list of all regions/cities e.t.c.
I have to somehow get the Reg_Name from tblRegion into Reg_Name in tblJob. I know this defeats the objective but I hHAVE to do it.
I have hundreds of records and I have no idea as to the syntax of the update query required.
Can anyone help ?
TIA
-
what is the DBMS? (Access/SQL-Server/other?)
-
-
pants.. never used MySQL :(
ah well, try this anyway:
Code:
UPDATE tblJob
SET Reg_Name = tblRegion.Reg_Name
FROM tblRegion
WHERE Reg_FK = tblRegion.Reg_PK
..actually, now I've written it I think it should be fine for all standard DBMS's
-
I get this :
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM tblregion
WHERE JOB_REGION = tblRegion.REGION_ID' at line
The query
UPDATE tblJob
SET JOB_REGIONTEXT = tblRegion.REGION_NAME
FROM tblregion
WHERE JOB_REGION = tblRegion.REGION_ID
Does MySQL like the '.' operator ?
-
alternative SQL for you to try:
Code:
UPDATE tblJob
SET JOB_REGIONTEXT = (Select REGION_NAME from tblRegion Where REGION_ID = JOB_REGION)
if it doesnt work, I think your best bet would be to check your documentation for the Update syntax.
I've read a few posts on this site that say something like 'MySQL doesnt fully support that yet', or 'you need version X.XX or above'. maybe you'll need to upgrade to be able to do it.
-
That's a very funny query. I told it to some of my coworkers, most of them laughed.