This works, but its still a nested query.  I wonder which syntax provides
the best performance, or if there is even a difference.

I think Yannick's real-world problem might be a stronger example.
Performing an aggregate function on the results of a UNION would require
nesting, right?

jaime

-----Original Message-----
From: Igor Tandetnik [mailto:[EMAIL PROTECTED] 
Sent: Sunday, April 08, 2007 10:55 PM
To: SQLite
Subject: [sqlite] Re: Nested SELECT : Alternative syntax please ?

Jaime Castells <[EMAIL PROTECTED]> wrote:
> Hmm, I think the only time you really can't avoid a nested query is
> when you 
> want to do a grouping function on the result of a grouping function. 
> Like 
> count the number of customers who have more than a certain number of
> orders. 
> Something like:
> 
> SELECT COUNT(cust.id)
> FROM (SELECT cust.id, COUNT(order.id) AS order_count FROM cust, order
> WHERE order.cust_id=cust.id GROUP BY cust.id)
> WHERE order_count>10
> ;

select count(cust.id) from cust
where (
    select count(*) from order
    where order.cust_id = cust.id) > 10;

Igor Tandetnik

----------------------------------------------------------------------------
-
To unsubscribe, send email to [EMAIL PROTECTED]
----------------------------------------------------------------------------
-



-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to