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

The Archive Base Latest Questions

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

I joined a table to itself to find duplicate rows select a.data, a.rowNumber, b.rowNumber

  • 0

I joined a table to itself to find duplicate rows

select a.data, a.rowNumber, b.rowNumber
from DuplicateRows as a
join DuplicateRows as b 
on
a.data = b.data and a.Id != b.Id
group by a.data, a.rowNumber, b.rowNumber

This query gives the results like

"content" | 1 | 2
"content" | 1 | 6
"content" | 2 | 1
"content" | 2 | 6 
...and so on

Howcome I rewrite it to have results formed like

"content" | 1 | 2, 6

EDIT

I think the question should be a little bit corrected.
You see I don’t want to get the inversed result, I mean I just want to get
one entry

`1 -> 2, 6` 

not

`1 -> 2, 6 and `2 -> 1, 6`

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-06-13T00:00:34+00:00Added an answer on June 13, 2026 at 12:00 am

    According to your latest edit, I think this is what you’ll be needing:

    SELECT a.data, a.a, GROUP_CONCAT( DISTINCT b.a)
    FROM TableName as a
    JOIN TableName as b 
        ON a.data = b.data AND a.a < b.a
    GROUP BY a.data
    

    SQLFiddle Demo

    PS

    I used(and modified) John Woo’s table a little bit.

    EDIT

    A relatively better results from this query:

    SELECT a.data, MIN(a.rowNumber), GROUP_CONCAT( DISTINCT b.rowNumber)
    FROM DuplicateRows AS a
    JOIN DuplicateRows AS b 
      ON a.data = b.data AND a.rowNumber < b.rowNumber
    GROUP BY a.data
    

    The fiddle is here.

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

Sidebar

Related Questions

Possible Duplicate: How to select rows where multiple joined table values meet selection criteria?
How to select additional column from joined table and send them all to View
I'm trying to collect data using the following query : SELECT * FROM `table1`
Using MySQL 5.x I want to efficiently select all rows from table X where
I have a SELECT request with 'inner join' in the joined table is a
I have two tables (Table A, Table B) joined with a join table (TableAB)
I am trying to get a single property from a joined table where a
I have a joined table from which I want to sum the attribute amounts
How can I efficiently update the table based on values from a join table
I want to use a where statement on a value from a joined table.

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.