autonomous increment in SQL?

Discussion in 'OT Technology' started by crotchfruit, Feb 28, 2004.

  1. crotchfruit

    crotchfruit Guest

    Is there a way to perform an autonomous increment in SQL (specifically MySQL)?

    The situation is this:

    I can do something like

    SELECT myint FROM table WHERE blah=blah2;
    ..get myint, put myint+1 into variable myintvar..
    UPDATE table SET myint = myintvar WHERE blah=blah2;

    Is there a way to increment it using 1 SQL statement? like:

    UPDATE table SET myint = (myint+1) WHERE blah=blah2;

    would this work? Can you reference a column value inside the update statement itself?
  2. Astro

    Astro Code Monkey

    Mar 18, 2000
    Likes Received:
    Cleveland Ohio
    Yup. That should work.
  3. crotchfruit

    crotchfruit Guest

Share This Page