0

So I'm fairly new to web development and I haven't really used php and mysql much before.

I was wanting to query my database to find out how many results had the same value for a certain field. I was thinking along the following lines:

SELECT value_a, COUNT(*)
FROM table_a
WHERE value_a = (SELECT DISTINCT value_a FROM table_a)

but obviously I can't have multiple values from my inner query. How could I do something like this?

Alec Gamble
  • 441
  • 3
  • 6
  • 16
  • Possible duplicate of [subquery returns more than 1 row](http://stackoverflow.com/questions/14841945/subquery-returns-more-than-1-row) – Nitish Feb 29 '16 at 12:41

2 Answers2

1

Simply do -

IF you want to check a single value -

SELECT COUNT(*) value_a_count
FROM table_a
WHERE value_a = 'value_to_check'
GROUP BY value_a

Or for every values -

SELECT value_a, COUNT(*) value_a_count
FROM table_a
GROUP BY value_a
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
0

put your result(check_value) in this query

SELECT COUNT(*) count_value
FROM table_a
WHERE value_a IN (check_value)
GROUP BY value_a
Vipin Jain
  • 3,686
  • 16
  • 35