Add an ID to a Table w/ Auto Increment

Posted on 2007-10-10
Medium Priority
Last Modified: 2013-12-13
Hello, I have 2 tables that I uploaded.  They have the same fields, but no id.  I want to combine them in a new table and I need to add an id to the table:

Table 'ContactsPart1':
first_name, last_name, phone

Table 'ContactsPart2':
first_name, last_name, phone

I want it to be:
Table 'ContactsAll'
id,first_name, last_name, phone

I copied ContactsPart1 structure and added id made it primary key and auto increment.

When I try the following command:
INSERT INTO `ContactsAll` SELECT first_name, last_name, phone FROM `ContactsPart1`

I get:
MySQL said:  
#1136 - Column count doesn't match value count at row 1

How do I get the info in to the new table w/ a SQL command and unique id for each record?  

I'm using php, but would rather do this through a SQL command.  Thank you for your time.
Question by:smoothcat11
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 2000 total points
ID: 20050757
INSERT INTO `ContactsAll` (first_name, last_name, phone) SELECT first_name, last_name, phone FROM `ContactsPart1`

Author Comment

ID: 20051018
YOU ARE AWESOME!!!  You just saved me so much time!  Thank you...

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

807 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