[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
SqlGroupBy

(SQL) group by

Command to group query results and/or get unique rows.

select * from database
where gender = 'female'
group by age


/* Example output: */
/* The youngest female is 16, the oldest 20 years old */
16
17
18
19
20


You can also count the age groups:

select *, count(*) from database
where gender = 'female'
group by age


/* Example output: */
/* The youngest female is 16, the oldest 20 years old */
/* The females' ages have a gaussian distribution     */
16 12 
17 25
18 50 
19 25
20 12


last edited (November 27, 2006) by bilderbikkel, Number of views: 860, Current Rev: 3 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.