1

The question basically means is how can we find duplicate values in a row? Example: I am making a blog website and in that, I want to display trending tags...

For this I created 2 tables:

  1. blog
  2. tag

in the blog table, my blog record is there, and in the tag table there are two columns

  1. id (PRIMARY)
  2. name
  3. blog_id

tag table

I want to display the top repeating names that come in the tag table. So, can you please just tell me what is the solution about it?

Like here Java repeats most time in the table. So, I just want the output to be like:

  1. JAVA
  2. Database
  3. PHP
Tejaswa
  • 11
  • 10
  • Search about SQL HAVING statement, combined with ORDER BY. Does It help you? – Canta Aug 08 '21 at 13:23
  • Ok. Let me check if it's working... But how can I use ORDER BY in that statement I don't want to recognize it alphabatically – Tejaswa Aug 08 '21 at 13:27
  • You probably just want to `ORDER BY` a `COUNT()` column, while you do a `GROUP BY` the name column. Just check this other SO answer: https://stackoverflow.com/questions/2283305/order-by-count-per-value – istepaniuk Aug 08 '21 at 13:37
  • 1
    Does this answer your question? [Order by COUNT per value](https://stackoverflow.com/questions/2283305/order-by-count-per-value) – istepaniuk Aug 08 '21 at 13:37
  • Order BY count(column) – Canta Aug 08 '21 at 13:38
  • Just wait. Let me check whether this post solves my query or not? – Tejaswa Aug 08 '21 at 13:40
  • Yes, it solves my question but it is quite different from other post questions. Wait for a while I will post answer of this question also.. – Tejaswa Aug 08 '21 at 13:47
  • To solve this problem just run this query : In my case this is : `SELECT count(name), name FROM `tag` GROUP BY name ORDER BY count(name) DESC` WHERE `name` is a column and `tag` is the table name – Tejaswa Aug 08 '21 at 13:58

0 Answers0