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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:28:54+00:00 2026-05-26T12:28:54+00:00

I have a table like this: | X | Y | Data | —————-

  • 0

I have a table like this:

| X | Y | Data |
----------------
| 1 | 2 | Hi   |
| 3 | 4 | Hey  |
| 1 | 2 | New! |
| 1 | 2 | New! |
| 1 | 2 | New! |

A little back story:

I am trying to create a table (HTML) using the co-ordinates specified in my table with the data in the cell body. Because the data isn’t specifically gotten by myself and comes from the users themselves (Grease monkey script pulling data from the site) I need to group the data by X and Y then group by the Data column and pick out the most occurring one.This is so I get legitimate data as they can spoof the data without me able to do anything about it.

The trouble being is finding a select query that will produce some sort of array like the following from the above table.

Array ( 
        [0] = Array ( 
           'x' => 1,
           'y' => 2,
           'Data' => "New!"   
         )
        [1] = Array ( 
           'x' => 3,
           'y' => 4,
           'Data' => "Hey"   
         )
      )

I did try a few variations but none worked so I’m checking here to see if anyone could shed some light on my problem.

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-26T12:28:54+00:00Added an answer on May 26, 2026 at 12:28 pm

    Does this work for you?

    SELECT T3.X, T3.Y, MAX(T3.Data) AS Data
    FROM
    (
        SELECT X, Y, MAX(cnt) AS max_cnt
        FROM
        (
            SELECT X, Y, Data, COUNT(*) AS cnt
            FROM yourtable
            GROUP BY X, Y, Data
        ) T1
        GROUP BY X, Y
    ) T2
    JOIN
    (
        SELECT X, Y, Data, COUNT(*) AS cnt
        FROM yourtable
        GROUP BY X, Y, Data
    ) T3
    ON T2.X = T3.X AND T2.Y = T3.Y AND T2.max_cnt = T3.cnt
    GROUP BY T3.X, T3.Y
    

    You may also want to consider creating a view:

    CREATE VIEW yourtable_counts AS
    SELECT X, Y, Data, COUNT(*) AS cnt
    FROM yourtable
    GROUP BY X, Y, Data
    

    Then you can simplify the query:

    SELECT T3.X, T3.Y, MAX(T3.Data) AS Data
    FROM
    (
        SELECT X, Y, MAX(cnt) AS max_cnt
        FROM yourtable_counts T1
        GROUP BY X, Y
    ) T2
    JOIN yourtable_counts T3
    ON T2.X = T3.X AND T2.Y = T3.Y AND T2.max_cnt = T3.cnt
    GROUP BY T3.X, T3.Y
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table like this: Application,Program,UsedObject It can have data like this: A,P1,ZZ
I have a table like this... CustomerID DBColumnName Data 1 FirstName Joe 1 MiddleName
I'm a bit confused on this. I have a data table structured like this:
i have a table data like this (int) (time) [mySQL datatype] Id Duration ------------------
Using MySQL 5 I have a table like this: date (varchar) door (varchar) shift
Let's say I have a table of users set up like this: CREATE TABLE
I have a postgres table like this: CREATE SEQUENCE seq; CREATE TABLE tbl (id
I have a table like this USER | DATA ---------------- User1 | 123 User1
If I have a table of data like this tableid author book pubdate 1
I have optimized a complex Oracle statement using temporary table like this : original

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.