Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL counting same strings

Tags:

sql

php

mysql

Example of MySQL columns data:

stringone
stringthree
stringtwo
stringone
stringone
stringthree

How can I get the following result from MySQL with PHP or mysql_ itself? I don't know strings content.

stringone    3x
stringthree  2x
stringtwo    1x

Thank you for your suggestions and direction.

like image 722
falcon Avatar asked Dec 26 '22 10:12

falcon


2 Answers

try this:

SELECT columnname1,count(columnname1) 
  FROM tablename 
   GROUP BY conlumnname1;

http://sqlfiddle.com/#!2/ecc99/1

like image 128
jmail Avatar answered Jan 06 '23 12:01

jmail


 SELECT string, COUNT(1) FROM table GROUP BY string
like image 23
potashin Avatar answered Jan 06 '23 10:01

potashin