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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:02:44+00:00 2026-05-14T01:02:44+00:00

Hi I have the following table T: id 1 2 3 4 col a

  • 0

Hi I have the following table T:

id    1   2    3    4
col   a   b    a    c

I want to do a select that returns the id,col when group by(col) having count(col)>1

One way of doing it is

SELECT id,col FROM T 
   WHERE col IN (SELECT col FROM T GROUP BY(col) HAVING COUNT(col)>1);

The intern select (from the right) returns ‘a’ and main one (left) will return 1,a and 3,a

The problem is that the where in statement seems to be extremely slow. In my real case, the results from the internal select has many ‘col’s, something about 70000 and it’s taking hours.

Right now it’s much faster to do the internal select and the main select getting all ids and upcs and do the intersection locally. MySQL should be able to handle this kind of query efficiently.

Can I substitute the where in for a join or something faster?

Thanks

  • 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-14T01:02:45+00:00Added an answer on May 14, 2026 at 1:02 am

    You could try if using an INNER JOIN speeds things up

    • Make sure you have an index on col
    • A covering index on col, id might gain you even better performance

    SQL Statement

    SELECT  T.id, T.col
    FROM    T
            INNER JOIN (
              SELECT   col
              FROM     T
              GROUP BY col
              HAVING COUNT(*) > 1
            ) tcol ON tcol.col = T.col
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following text that I want to capture as a table: question,answer
I have the following string expression in a PowerShell script: select count(*) cnt from
I have the following query: SELECT * FROM table_name WHERE (col_1 LIKE '%$keyword%' OR
We have the following XHTML table: <tr class=encabezado> <th scope=col width=2%>1</th> <th scope=col width=2%>2</th>
I have the following xml that stores table definations. How can I loop through
I have view that contains a table with the following structure: <table id=mappings> <thead>
I have the following XML (partial) document : <export> <table name=CLIENT> <row> <col name=CODE_CLIENT
I have the following Execution statement which creates a table (using data from another
given the following information I have in a database table: Col 1, Col2, Col3
I have the following code: <table id=box-table-a class=tablesorter> <thead> <tr> <th scope=col>B-House/Dorm Name</th> <th

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.