how to get the count and name of each element

291
January 18, 2017, at 00:38 AM

Here I have a situation where I'm not certain about the field elements.

suppose I have this dynamic fields

table:mytable

+my_column_name+
 |"colleges"|
 |"schools" |
 |"global"  |
 |"temple"  |
    .
    .
    .
 |"business"|

I'm trying to get all the fields as well as count.

SELECT count()
   FROM mytable
   WHERE my_column_name = 

Please help me to dynamically get all fields, thanks a lot!!!

Answer 1

Those aren't fields, they are just data values. As far as understand your question, this should be solved with a simple group-by query:

SELECT my_column_name as `what_you_call_field`, COUNT(*)
FROM mytable
GROUP BY my_column_name;

If you mean something different, please edit your question above and post an example of what you want a hypothetical query result to look like.

READ ALSO
Warning: Invalid argument supplied for foreach()

Warning: Invalid argument supplied for foreach()

I have an error in the product detail, I do not know what else to change where againwhen I change $detail into $categories succeed but is the same as function submenu

287
PHP - Not showing all rows from database

PHP - Not showing all rows from database

I have the following code which is supposed to get several records from the databaseWhen the query is ran in phpmyadmin it displays the rows fine, but on the page it only displays the first item

225
How to build a mySQL query with three different tables with timespan, summarizing and grouping of values

How to build a mySQL query with three different tables with timespan, summarizing and grouping of values

My first question here and with very little knowledge of programming so please bear with me

186
LIMT query to 1 if selcted two tables

LIMT query to 1 if selcted two tables

How to limit query to 100 if i have selected data from two tables

173