Web Hosting Talk







View Full Version : select


tea_clipper
02-22-2008, 11:28 PM
good day

i came across this code
"$query = "select count(*) from tablename group by type"

can i add more than one field on the "group by type" is that posible like this:

$query = "select count(*) from tablename group by date_sold,customerid";

is this possible

tnx

Codebird
02-23-2008, 07:01 AM
yes you can

wdr1
02-23-2008, 04:39 PM
You can, but I don't think it does what you want -- it's not going to change the result. Are you trying to order counts by date?

If some, it should be something like:

select date_sold, count(*) as tally from tablename group by date_sold

I would guess you'd want it sorted as well, so for by date:

select date_sold, count(*) as tally from tablename group by date_sold order by date_sold

or by orders (from biggest to smallest):

select date_sold, count(*) as tally from tablename group by date_sold order by tally desc

Hope that helps,
-Bill

Codebird
02-23-2008, 05:59 PM
he's asking if he can group by two fields you grouped by one!

jamesmoey
02-24-2008, 08:43 PM
wdr1 why you say the result is not going to change?

the result definitely going to change, now that you are group using 2 column.