1

I have two table in sql database like below:

Table 1 : event table          Table 2 : game table

|event_id | game_id |         |game_id | game_name |
|  140    |  10     |         |  10    | football  |
|  140    |  10     |         |  11    | Cricket   |
|  140    |  10     |
|  140    |  10     |
|  140    |  11     |
|  140    |  11     |
|  140    |  11     |

Now i want the result like below:

|game_name | Count |
| football |   4   |
| Cricket  |   3   |

I have tried the query:

SELECT g.g_name, count(g.g_name) FROM game_table g INNER JOIN event_table e ON g.game_id = e.game_id WHERE event_id = '140';

but this query is given me total count not particular count of particular game name. so how can i find counts of particular game_name?

2
  • Your query is fine, just add GROUP BY g.g_name Commented Oct 6, 2016 at 13:05
  • @YourCommonSense, Amazing it is working.. thanks buddy. Commented Oct 6, 2016 at 13:09

1 Answer 1

1

You need to have GROUP BY clause

SELECT g.g_name, count(g.g_name) 
FROM game_table g INNER JOIN event_table e ON g.game_id = e.game_id 
WHERE event_id = '140'
GROUP BY g.g_name;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.