Hi all,
i am experimenting on the online tool, SQLcourse 2 tutorial, and have
entered the following query,
SELECT lastname, item, quantity, price
FROM items_ordered, customers
GROUP BY lastname DESC;
the answer I get looks like this,
Smith Pogo stick 1 28.00
Schultz Pogo stick 1 28.00
Sanchez Pogo stick 1 28.00
Sakahara Pogo stick 1 28.00
Moore Pogo stick 1 28.00
Mendoza Pogo stick 1 28.00
Keller Pogo stick 1 28.00
Jones Pogo stick 1 28.00
Howell Pogo stick 1 28.00
Gray Pogo stick 1 28.00
Graham Pogo stick 1 28.00
Giles Pogo stick 1 28.00
Davids Pogo stick 1 28.00
Dalton Pogo stick 1 28.00
Cleaver Pogo stick 1 28.00
Brown Pogo stick 1 28.00
DB shows only one pogo stick sold ( to dalton)
help
Bob Badour - 23 Jan 2004 22:08 GMT
> Hi all,
>
[quoted text clipped - 25 lines]
>
> DB shows only one pogo stick sold ( to dalton)
You have a cartesian product between items_ordered and customers. You will
need a where clause or join/on clause to specify how to match items_ordered
with customers.
Also, you only group by one of the non-aggregate fields, which is an error
even if your SQL parser fails to identify the error.
shannon - 23 Jan 2004 22:28 GMT
thanks bob,
WHERE customers . customerid = items_ordered . customerid
aah the theory is starting to click in
>>Hi all,
>>
[quoted text clipped - 32 lines]
> Also, you only group by one of the non-aggregate fields, which is an error
> even if your SQL parser fails to identify the error.