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 3214116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:01:21+00:00 2026-05-17T15:01:21+00:00

Sounds simple but I’m stuck Table A Table B col_a col_b col_a col_c 1

  • 0

Sounds simple but I’m stuck

Table A                 Table B

col_a  col_b          col_a  col_c
1      b              1      c
2      c              2      d
3      z              3      a
4      d              4      e
33     a              5      k
                      6      l
                      33     b
                      33     b

I want to JOIN table A with B:

select * from A inner join B on A.col_a = B.col_a

I am expecting to get 5 records as a result.

Expected join result         ** Actual result **

col_a  col_b col_c col_x[n]...       col_a col_b col_c  col_y[n]...
1      b     c     ...                   1     b     c  ...
2      c     d     ...                   2     c     d  ...
3      z     a     ...                   3     z     a  ...
4      d     e     ...                   4     d     e  ...
33     a     b     ...                   33    a     b  ...
                                         33    a     b  ...

Why did MySQL match 33 twice? Because they are 2 values with 33 in table B.

What I want though, is just one record with the same value in col_a. How do I do that?

EDIT: I am updating the tables’ design to include more columns that contain non-identical data, because them being as they were posed more questions than solved problems. Anyway, the answer to this is to use GROUP BY, but the performance penalty is huge, especially on a table that contains above 50 million records (and growing).
However, the best approach to solve my problem was to use a compound statement (using UNION ALL) for every distinct value in col_a. The performance benefit was x5 ~ x10 faster !!

  • 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-17T15:01:22+00:00Added an answer on May 17, 2026 at 3:01 pm

    You have 33 twice in Table B.

    Either SELECT DISTINCT or GROUP BY col_a, ...:

    SELECT DISTINCT * 
    FROM    A 
    JOIN    B ON ( A.col_a = B.col_a )
    ;
    

    or

    SELECT    * 
    FROM      A 
    JOIN      B ON ( A.col_a = B.col_a )
    GROUP BY  col_a, col_b, col_c
    ;
    

    You should clean up that table, though.
    Depending on how many occurrences of a repeated row, it might be faster to use a subquery:

    SELECT  * 
    FROM    A 
    JOIN    (select distinct * from B) AS C
            ON ( A.col_a = C.col_a )
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This sounds simple but my regex knowledge is limited. I need an expression to
this sounds really simple and stupid..but I'm having a hard time removing the content
This sounds like a simple question, but I don't know how to search for
Sounds simple but it's giving me grief: Tried this: function validateAddress() { if (!($('<%=txtPlaceName.ClientID%>').val()
This sounds like a simple question but I can't find good information. I'm writing
This question sounds simple, but I'm an expert with CSS and I'm thinking it's
I think I've got what sounds like a simple request but is probably actually
this sounds simple but drives me nuts. I am on Windows 7 and have
Sounds simple enough...but I've been plugging away at this, trying to find the one
This sounds really simple but it's like an onion - lots of layers as

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.