how to use group by in two ield in mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

how to use group by in two ield in mysql

Post by manojsemwal1 »

hai i have a table where student enter accordingly to their category and instituteid wise .

i want to see the student report to their category and instituteid wise how to make a query.........
i ran the follow query.........
SELECT Category, COUNT( StudentID ) AS Sum
FROM studentregdtb
GROUP BY Category
LIMIT 0 , 30

its gives only category wise student sum record.....but how to get in institutewise also..........

thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: how to use group by in two ield in mysql

Post by Christopher »

Add instituteid to the GROUP BY. See the docs.
(#10850)
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: how to use group by in two ield in mysql

Post by mikosiko »

Try this

Code: Select all

SELECT InstituteId, Category, COUNT( StudentID ) AS Sum
FROM studentregdtb
GROUP BY InstituteId,Category
LIMIT 0 , 30
Post Reply