Results 1 to 5 of 5

Thread: [RESOLVED] MySQL Insert issue

  1. #1

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Resolved [RESOLVED] MySQL Insert issue

    Hello guys.
    I would like to know another way for doing this insert instruction, without using the 'select ...' as value.
    My version of MySQL doesn't allow this.

    Code:
    insert into calls 
    	(id, date_entered, date_modified, name)
    values
    	((select max(id)+1 from calls), now(), now(),  'name')
    Thank u

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: MySQL Insert issue

    The simplest method is to make that field an AutoNumber/Identity in the table design - that way the database system itself will automatically add the next number (and wont make any mistakes if multiple users add a record at the same time).

    You then just remove the field (and value) from your Insert statement.

  3. #3

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: MySQL Insert issue

    I know that but I can't change the the table design. I'm not allowed to do that.
    Anyway, thank's for for the tip.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: MySQL Insert issue

    OK, well in that case try the usual syntax for an Insert/Select, eg:
    Code:
    insert into calls 
    	(id, date_entered, date_modified, name)
    select max(id)+1, now(), now(),  'name' from calls

  5. #5

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: MySQL Insert issue

    Thank u.
    That's it!!
    So simple...

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