SQL Query to achieve a total count value

Hi

I have an SQL query question and I just cannot work out how to pull the total correctly for this query. Effectively I am wanting to return a COUNT where the COUNT total is the total of the following two SQL queries;

SELECT COUNT(*) FROM wp_usermeta WHERE meta_value = 'Hub'

SELECT COUNT(*) FROM wp_usermeta WHERE meta_value = 'London'

I am trying to find how many times both of those values exist but joined by the user_id being equal.

So for example - If user one has two meta_value (s) assigned to their user_id of Hub and Birmingham this would not give any count total because that user_id does not have both values correct, it only has one.

If user two has two meta_value (s) assigned to their user_id of Hub and London this would return a value of 1 count total because that user_id has both values correct.

If user three has two meta_value (s) assigned to their user_id of Hub and London this would return a value of 1 count total because that user_id has both values correct.

The total count would now be at 2 as we have two user_id's that have both meta_value (s) correct.

Ideally I would like to tie these into the meta_key values of user_area and user_role so that other instances within the meta_value table do not get added.

In summary

meta_key.user_area should = a meta_value of London
meta_key.user_role should = a meta_value of Hub

When both instances exist tied to the same wp_usermeta.user_id it should return a value of 1, if any part is not right it should ignore and not count.

Appreciate this is just General Wordpress support but hey, that's what you market :slight_smile:

Thanks in advance to the SQL Wordpress Wizards

Regards

Wayne