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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:51:43+00:00 2026-06-04T22:51:43+00:00

Below is what I have in table myTable . +——–+——–+——–+——–+ | value1 | value2

  • 0

Below is what I have in table myTable.

+--------+--------+--------+--------+
| value1 | value2 | value3 | value4 |
+--------+--------+--------+--------+
|   9    |   4    |   3    |   3    |
|   1    |   2    |   9    |   3    |
|   1    |   2    |   3    |   4    |
|   1    |   2    |   3    |   4    |
+--------+--------+--------+--------+

I want output as

+--------+--------+--------+--------+
| value1 | value2 | value3 | value4 |
+--------+--------+--------+--------+
|   1    |   2    |   3    |   4    |
+--------+--------+--------+--------+

value1=1 because 1 is thrice in that column.

value2=2 because 2 is thrice in that column.

value3=3 because 3 is thrice in that column.

value4=4 because 4 is twice in that column and that is maximum number of all common number in that column.

NOTE : value4 has most common values as 3 and 4. In output I should get 4 as 4 is the greatest in 3,4.

Can I achieve this in mysql?

Update 1

Table at SQL Fiddle

Update 2

I am listing answer here also so that no need to go on js-fiddle. (as per @ypercube answer)

SELECT
  ( SELECT value1
    FROM myTable
    GROUP BY value1
    ORDER BY COUNT(*) DESC
           , value1 DESC
    LIMIT 1
  ) AS value1,

  ( SELECT value2
    FROM myTable
    GROUP BY value2
    ORDER BY COUNT(*) DESC
           , value2 DESC
    LIMIT 1
  ) AS value2,

  ( SELECT value3
    FROM myTable
    GROUP BY value3
    ORDER BY COUNT(*) DESC
           , value3 DESC
    LIMIT 1
  ) AS value3,

  ( SELECT value4
    FROM myTable
    GROUP BY value4
    ORDER BY COUNT(*) DESC
           , value4 DESC
    LIMIT 1
  ) AS value4
;
  • 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-04T22:51:45+00:00Added an answer on June 4, 2026 at 10:51 pm
    SELECT
      ( SELECT value1
        FROM myTable
        GROUP BY value1
        ORDER BY COUNT(*) DESC
               , value1 DESC
        LIMIT 1
      ) AS value1,
    
      ( SELECT value2
        FROM myTable
        GROUP BY value2
        ORDER BY COUNT(*) DESC
               , value2 DESC
        LIMIT 1
      ) AS value2,
    ...
      ( SELECT valueN
        FROM myTable
        GROUP BY valueN
        ORDER BY COUNT(*) DESC
               , valueN DESC
        LIMIT 1
      ) AS valueN
    ;
    

    SQL-Fiddle: test-2

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

Sidebar

Related Questions

Suppose I have a table MYtable as given below: ID A B C 1
I have a table was named MYTABLE. That have two columns FIRSTNAME and LASTNAME.
I have a table as below; <table id=mytable cellpadding=0 cellspacing=0> <tr> <td>&nbsp;</td> <td><input type=text
I have a table as below; <table id=mytable> <tr> <td>cola1</td> <td>cola2</td> <td>cola3</td> <td class=rem>cola4</td>
I have a table like below <table id=mytable> <tr><th>checked</th><th>id</th><th>text</th></tr> <tr><td><input id=cb1 type=checkbox name=checker1/></td><td>123</td><td>abc</td></tr> <tr><td><input
Below is what I have in my table. myTable ++++++++++++++++++++ Parent + Child ++++++++++++++++++++
I have a table like below: MyTable -------- A B C A,B,C are columns
How do I select in a table like below all objects that have a-A
edit: my table schema below is poorly normalized as suggested and I have revamped
need help in error in database pivot. i have table tamed table_score like below:

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.