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

  • Home
  • SEARCH
  • 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 5957625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:25:39+00:00 2026-05-22T18:25:39+00:00

I’m running this query: CREATE TABLE SELECT people.*, Sheet1.department FROM people LEFT JOIN Sheet1

  • 0

I’m running this query:

CREATE TABLE
SELECT people.*, Sheet1.department
  FROM people LEFT JOIN Sheet1 ON people.depno = Sheet1.depno

On a set of tables detailing employee records.

The goal is to create a new table that has all the “people” data, plus a human-readable department name. Simple, right?

The problem is that each record in the resulting table appears to be duplicated exactly (with literally every field being the same), turning a roughly 23,000-record table into a roughly 46,000-record table. I say “roughly” because it’s not an exact doubling — there’s a difference of about a hundred records.

Some details: The “people” table contains 15 fields, including the “depno” field, which is an integer indicating department.

The “Sheet1” table is, as one would guess, a table generated from an imported xls file containing two fields: the shared “depno” and a new “department” (the latter being a verbose department name corresponding to the depno in question). There are 44 records in the “Sheet1” table.

Thanks in advance for any pointers on this. Let me know what other information you can use from me.


Update: Here’s the code I ended up using, from my response to Johan (thanks again to everyone who worked on this):

CREATE TABLE morebetter 
    SELECT people.*, Sheet1.department FROM people 
    LEFT JOIN Sheet1 ON people.depno = Sheet1.depno 
    GROUP BY id 
  • 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-05-22T18:25:40+00:00Added an answer on May 22, 2026 at 6:25 pm

    The people.depno is not unique, that’s why you’re getting the doubling.

    Change the SELECT part to

    SELECT DISTINCT people.*, Sheet1.department
      FROM people LEFT JOIN Sheet1 ON people.depno = Sheet1.depno
    

    This will eliminate duplicate rows.

    In MySQL you can also write

    SELECT people.*, Sheet1.department
    FROM people LEFT JOIN Sheet1 ON people.depno = Sheet1.depno
    GROUP BY people.depno
    

    Which works slightly different.
    The first query eliminates rows with duplicate output, the second query eliminates records with duplicate people.depno, even if people.depno does not appear in the output.

    I like the second form, because it makes explicit which duplicate you’re trying to eliminate and you don’t need to tweak the output.
    It’s also slightly faster in executing time.

    ***Warning***
    The group by version will eliminate any double people.depno it finds, but if the other fields in the select are not identical it will just choose one at random!
    In other words. If the outcome of the select distinct is different from the group by version that means that MySQL is silently dropping non-duplicate rows.
    This may or may not be what you want!

    In order to be safe, do a group by on all fields that you care about!
    If the group by is on a unique key than it’s pointless to include further fields from the same table as that unique key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.