February 16, 2006 at 11:17 am
I know it is probably something easy, but I am having trouble with an order by clause. Any help and explanation of why would be greatly appreciated. Thank you in advanced.
select distince p.id, p.comment, t.qty, t.amount, pr.name, t.time
from people p, transactions t, printers pr
where p.user_id = '52746'
and p.user_id = t.user_id
and t.ref_id = pr.printer_id
gropu by pr.name
order by t.time desc
ERROR: column 'name' is invalid in the select list because it is not contained in either an aggregate function or the group by clause.
I have tried adding each column name to the order by clause, but I still receive an error.
February 16, 2006 at 12:39 pm
Because you aren't performing any aggregate functions (sum(), count(), min(), ...), you don't need to use GROUP BY. The DISTINCT will take care of it.
Otherwise, you will need to add all of the non-aggregated columns in the SELECT list to the GROUP BY list.
Eddie Wuerch
MCM: SQL
February 17, 2006 at 7:12 am
You also spelled "DISTINCT" wrong in your example:
select distince p.id, p.comment, t.qty, t.amount, pr.name, t.time
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply