selecting unique records

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
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

selecting unique records

Post by michlcamp »

I've got a database table named 'sales' where each sale has these fields:

id, item,price,salesperson

table looks like:

1 item1 2.00 bob
2 item2 3.00 bob
3 item3 4.00 bob

I want to display:

Code: Select all

---------------------
|salesperson | total |
---------------------
| bob       | 9.00 |
----------------------
how do I write the query?

Any help appreciated..
thanks.
mc
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

SELECT  `salesperson`, SUM(`price`) AS `total` FROM `salesperson` GROUP BY `salesperson`


moved to Databases.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

feyd wrote:

Code: Select all

SELECT  `salesperson`, SUM(`price`) AS `total` FROM `salesperson` GROUP BY `salesperson`
moved to Databases.
[GROUP BY] => what will it do ?
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

Post by michlcamp »

Thanks much. works great.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

itsmani1 wrote:[GROUP BY] => what will it do ?
The manual has all the info you need: http://dev.mysql.com/doc/mysql/en/select.html
Post Reply