Why can't you use the group by and having clause right on the main
query? How about something like this:

SELECT orders.*, payment_authority.*
FROM orders LEFT OUTER JOIN payment_authority
ON orders.order_id = payment_authority.order_id
WHERE orders.order_receipt_sent = 1
GROUP BY customer_id, orders.order_id, [rest of columns here]
HAVING count(orders.order_id) > 1
ORDER BY orders.customer_id

Of course, your schema is not particularly clear to me
(payment_authority is your customer table?), so I may be totally off
here.

Cheers,
Kris


> My client wishes to see all customers that have made more than 1 order
> from their website. What I have is the following...
>
> SELECT orders.*, payment_authority.*
> FROM orders LEFT OUTER JOIN payment_authority
> ON orders.order_id = payment_authority.order_id
> WHERE orders.order_id IN
> (
>         SELECT O.order_id FROM orders AS O
>         WHERE Exists (
>                 SELECT customer_id
>                 FROM orders
>                 WHERE orders.customer_id = O.customer_id
>                 GROUP BY orders.customer_id
>                 HAVING COUNT(orders.customer_id) > 1
>         )
> )
> AND orders.order_receipt_sent = 1
> ORDER BY orders.customer_id

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:249715
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to