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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:49:35+00:00 2026-05-19T21:49:35+00:00

I have a table with around 15 columns. What I would like to be

  • 0

I have a table with around 15 columns. What I would like to be able to do, is select a range of IDs and have all column data that is the same, presented to me.

At the minute, I have it structured as the following:

SELECT id, col_a, col_b ... count(id)
FROM table
GROUP BY col_a, col_b ... 

Which returns rows grouped together that have identical data within all the rows – which is half what I want, but ideally I would like to be able to get a single row with either the value (if it’s the same for every row id) or NULL if there is a single difference.

I’m not sure that it is possible, but I would rather see if it’s doable in an SQL query than write some looping logic for PHP to go through and check each row’s similarity.

Thanks,

Dan

UPDATE:

Just to keep this up-to-date, I worked through the problem by writing a PHP function that would find which were duplicates and then display the differences. However I have now since made a table for each column, and made the columns as references to the other tables.

E.G. In MainTable, ColA now refers to the table ColA

I’m still solving the problem with the PHP for the time being, mainly as I think it still leaves the problem mentioned above, but at least now Im not storing duplicate information.

  • 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-19T21:49:35+00:00Added an answer on May 19, 2026 at 9:49 pm

    Its a hairy thing to do, but you could do it similarly to how David Martensson suggested, I would write it like this, however:

    Select a.id, a.col1, a.col2, a.col3
    FROM myTable a, myTable b
    WHERE a.id != b.id
    and a.col1 = b.col1
    and a.col2 = b.col2
    and a.col3 = b.col3
    

    That would give you the ids that are unique, but each result would have the same values for columns 1, 2, and 3. However, I agree with some of the commenters to your question that you should consider an alternative data structure, as this could better take advantage of an RDBMS model. In that case you would want to have 2 tables:

    Table name: MyTableIds
    Fields: id, attrId

    Table name: MyTableAttrs
    Fields: attrId, attr1, attr2, attr3, ect

    In general, if you have data that is going to be duplicated for multiple records, you should pull it into a second table and create a relationship so that you only have to store the duplicated data 1 time and then reference it multiple times.

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

Sidebar

Related Questions

I have a lab values table that I would like to query and get
I would like to have space around the content, inside the border of the
I have a table with a variable number of columns that I want to
I have table with 50 entries (users with such details like Name Surname Location
I have table rows of data in html being filled from a CGI application.
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
I have a table in a SQL Server 2005 database with a trigger that
I have an application where users can select a variety of interests from around
I'm helping implement a SQL Server 2008 database and I have several columns that
I have some CSV data files that I want to import into mySQL. I

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.