Skip to content
Advertisement

Is there a way I can get output of count values in MySql?

I am dealing with getting the output of some common values. My database is quite big so I am just giving a dummy database here for understanding purposes.

Here is the table I have:

I have to extract only those variables that have the given common room numbers alotted. This is the table for the required data:

Its output should be like this:

A and E, both variables have common room values i.e. 101 and 103

I came up with this query:

I have to print this, ones with count as 2!!

Any help would be appreciated.

Advertisement

Answer

I have to extract only those variables that have the given common room numbers allotted.

I don’t know what your table or columns are called, but you can use aggregation and having:

If duplicates are allowed in the data, then use count(distinct col2) in the having clause.

If these values are stored in a second table, then just use:

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