Skip to content
Advertisement

Get a count of individual instances of a value in MySQL

I have a table with two fields, inbound and outbound, both of which are text values. I want to get all a count of all instances of a specific value in either or both of those columns.

Here’s an example of the schema with some values and my query:

Here’s an SQL fiddle with the schema and my current query

Currently I’m getting a count of 3 appearances of my_widget, however I want to count all 5 appearances of my_widget

Advertisement

Answer

You can do something like this with case statement, here is the demo.

Output:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement