Is there a mySQL equiv to SQL Server's  select identity(int,1,1) as ...

Posted on 2009-04-15
Last Modified: 2012-05-06
I'm porting a project from SQL Server to mySQL.

In SQL Server:
"Select identity(int,1,1) as id,  a, b, c  INTO newTable from oldTable" creates an autoNumbered id column.

In MySQL: ?

If there's no equivalent way, I suppose I could create an empty table with an autoNumber field and then insert into it.
Question by:studioEtc
    LVL 50

    Accepted Solution

    Actually, it's a bit of both.  Take a look here:
    LVL 14

    Assisted Solution

    SET @i = 0;
    INSERT INTO ....
    SELECT @i= @i+1 as i, col2 ....

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now