Subquery [message #20408] |
Tue, 21 May 2002 11:11 |
ckr
Messages: 13 Registered: May 2002
|
Junior Member |
|
|
hai,
I have two tables Orders and Customers which are related by Cust_id.here i just want to know the total no of orders placed by each customer.
I used the query
select cust_name,cust_state,
(select count(*)
from orders
where orders.cust_id=customers.cust_id) as orders
from customers
order by cust_name;
the result is 'missing expression ' at subquery.
is there anything wrong with this query
please help me
|
|
|
Re: Subquery [message #20409 is a reply to message #20408] |
Tue, 21 May 2002 13:07 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
select c.cust_name, c.cust_state, count(*) order_count
from customers c, orders o
where o.cust_id = c.cust_id
group by c.cust_name, c.cust_state;
|
|
|