Results 1 to 7 of 7

Thread: Funny query problem

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    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

    Parksie

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    what is the DBMS? (Access/SQL-Server/other?)

  3. #3

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    MYSQL

    Parksie

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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

  5. #5

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    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 ?

    Parksie

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    That's a very funny query. I told it to some of my coworkers, most of them laughed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width