Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8694401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:46:47+00:00 2026-06-13T00:46:47+00:00

I have two TABLEs from the US Census. One has 2.8 millions records in

  • 0

I have two TABLEs from the US Census. One has 2.8 millions records in it, which is not only too large it contains data I simply don’t need such as the 9-digit Zip Codes. I want to create a new table without the 9-digit Zip Codes, instead the 5-digit Zip Codes. I’m having trouble here, it might simply be the syntax, but I would greatly appreciate the help.

This query works to list all the rows:

SELECT DISTINCT ZIP5, 
STATE_CODE,STATE,
COUNTY_CODE,COUNTY_NAME,
CBSA_CODE,CBSA_TITLE, CBSA_LSAD,
METRO_DIVISION_CODE, METRO_DIVISION_TITLE, METRO_DIVISION_LSAD,
CSA_CODE, CSA_TITLE, CSA_LSAD
from zip_code_to_cbsa;

I created the TABLE in PHP:

$sql = 'CREATE TABLE `zip5_code_to_cbsa` (
`id` INT unsigned NOT NULL AUTO_INCREMENT,
`ZIP5` VARCHAR(5) NOT NULL,
`STATE_CODE` VARCHAR(2) NOT NULL,
`STATE` VARCHAR(2) NOT NULL,
`COUNTY_CODE` VARCHAR(3) NOT NULL,
`COUNTY_NAME` VARCHAR(50) NOT NULL,
`CBSA_CODE` VARCHAR(5) NOT NULL,
`CBSA_TITLE` VARCHAR(50) NOT NULL,
`CBSA_LSAD` VARCHAR(50) NOT NULL,
`METRO_DIVISION_CODE` VARCHAR(5) NOT NULL,
`METRO_DIVISION_TITLE` VARCHAR(50) NOT NULL,
`METRO_DIVISION_LSAD` VARCHAR(50) NOT NULL,
`CSA_CODE` VARCHAR(3) NOT NULL,
`CSA_TITLE` VARCHAR(50) NOT NULL,
`CSA_LSAD` VARCHAR(50) NOT NULL,
 primary key (id,ZIP5)
   )';

Now to do the INSERT I attempted the following which gives an error:

INSERT into zip5_code_to_cbsa
SELECT DISTINCT ZIP5, 
STATE_CODE,STATE,
COUNTY_CODE,COUNTY_NAME,
CBSA_CODE,CBSA_TITLE, CBSA_LSAD,
METRO_DIVISION_CODE, METRO_DIVISION_TITLE, METRO_DIVISION_LSAD,
CSA_CODE, CSA_TITLE, CSA_LSAD
from zip_code_to_cbsa;

mysql>     INSERT into zip5_code_to_cbsa
->     SELECT DISTINCT ZIP5, 
->     STATE_CODE,STATE,
->     COUNTY_CODE,COUNTY_NAME,
->     CBSA_CODE,CBSA_TITLE, CBSA_LSAD,
->     METRO_DIVISION_CODE, METRO_DIVISION_TITLE, METRO_DIVISION_LSAD,
->     CSA_CODE, CSA_TITLE, CSA_LSAD
->     from zip_code_to_cbsa;
**ERROR 1136 (21S01): Column count doesn't match value count at row 1**
mysql> 

Thanks!

UPDATE:

This appears to be working for me now, unless someone can find a problem with it?

$sql = 'INSERT into zip5_code_to_cbsa (ZIP5,STATE_CODE,STATE,
COUNTY_CODE,COUNTY_NAME,
CBSA_CODE,CBSA_TITLE, CBSA_LSAD,
METRO_DIVISION_CODE, METRO_DIVISION_TITLE, METRO_DIVISION_LSAD,
CSA_CODE, CSA_TITLE, CSA_LSAD)
SELECT DISTINCT ZIP5 as ZIP5,
STATE_CODE,STATE,
COUNTY_CODE,COUNTY_NAME,
CBSA_CODE,CBSA_TITLE, CBSA_LSAD,
METRO_DIVISION_CODE, METRO_DIVISION_TITLE, METRO_DIVISION_LSAD,
CSA_CODE, CSA_TITLE, CSA_LSAD
from zip_code_to_cbsa;
';

The SELECT DISTINCT ZIP5 as ZIP5 allowed me to include the DISTINCT as part of this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:46:48+00:00Added an answer on June 13, 2026 at 12:46 am

    You need to specify the column names explicitly if you are inserting to selected columns only,

    INSERT INTO tableName (colA, colB)
    SELECT colA, colB
    FROM tableName
    

    what you are doing now is incorrect because the server assumes that you are inserting a value to all columns but you have supplied less than the number columns, that’s why it generate an error

    Column count doesn't match value count
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables and their only difference is one column is missing from
I have two tables, one that has a foreign key from the other. I
So I have two tables, article and comments (which has one-to-many relationship (1 article
I have two different tables from which I need to pull data blogs which
I have two tables services and member_services To fetch records from member_services where member_type_id
I have the query to select some columns from two tables, which must contain
I have two tables from the same DB that when one field is updated,
I have two tables: Accounts , which contains the information of accounts that a
I have two tables, each one has a primary ID column as key. I
I have two tables in my database named...Requests and Balance tracker which has no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.