Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2004
    Posts
    14

    Unanswered: sql problem. Help please

    SQL problem in mysql
    INSERT INTO task (user_id, poster_id, project_id, mount_id, subject, time, finish, priority_id, type_id, status_id) VALUES (999, 999, 111, (select MAX(ID) from task where subject = 'Software', 'training', -1, -1, 2, 2, 1);

    and

    UPDATE task SET mount_id = 2
    Where Id = select Max(ID) from task where subject ='Consulting';

    they both gave me this error :

    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 'select Max(ID) from task where subject ='Consulting'' at line 1

    Please and Thank You

  2. #2
    Join Date
    Oct 2003
    Location
    Slovakia
    Posts
    482

    Re: sql problem. Help please

    Originally posted by Paingiver
    SQL problem in mysql
    INSERT INTO task (user_id, poster_id, project_id, mount_id, subject, time, finish, priority_id, type_id, status_id) VALUES (999, 999, 111, (select MAX(ID) from task where subject = 'Software', 'training', -1, -1, 2, 2, 1);

    and

    UPDATE task SET mount_id = 2
    Where Id = select Max(ID) from task where subject ='Consulting';

    they both gave me this error :

    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 'select Max(ID) from task where subject ='Consulting'' at line 1

    Please and Thank You
    What version of MySQL you are using? Because subselects (nested queries) are supported only 4.1.x and newer version

  3. #3
    Join Date
    Feb 2004
    Location
    Erehwon
    Posts
    18
    Don't know about the second query, but you didn't close the parens around the subquery in your first one

    [code]
    INSERT INTO task (user_id, poster_id, project_id, mount_id, subject, time, finish, priority_id, type_id, status_id) VALUES (999, 999, 111, (select MAX(ID) from task where subject = 'Software'), 'training', -1, -1, 2, 2, 1);
    [\code]

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    PHP Code:
    insert 
      into task 
         
    user_id
         
    poster_id
         
    project_id
         
    mount_id
         
    subject
         
    time
         
    finish
         
    priority_id
         
    type_id
         
    status_id
         

    select 999
         
    999
         
    111
         
    max(id
         , 
    'training'
         
    , -1
         
    , -1
         
    2
         
    2
         
    1
      from task
     where subject 
    'Software' 
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Feb 2004
    Posts
    14
    MySql v 4.0.17, so i guess i should update my mysql. I'm downloading it now.

  6. #6
    Join Date
    Feb 2004
    Posts
    14
    To Ursus,

    Yes i did close the statement.

    Thank You

  7. #7
    Join Date
    Feb 2004
    Posts
    14
    After updating mysql to v 5.0.0a i now have this error:

    You can't specify target table 'task' for update in FROM clause

Posting Permissions

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