I want to write one mysql query to fetch all my table data and with total records count.
For eg. this is my table
ID Name typeId
1 test1 1
2 test2 1
3 test3 2
If I am going to fetch data with type id 1 I need a result like this
Name count
test1 2
test2 2
How can I write sql for this kind of a result.
I dont want subquery. I want to fetch data with out subquery
Please help me.
Thanks
Looking at your desired result this is a bizarre requirement as you want all count(not for each
Name). You can use sub-query for that:Or if you want count for each
Nametry this:EDIT:
As you have updated your question your query should be like this:
See this SQLFiddle