Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / General DB Topics / General DB Topics / July 2004

Tip: Looking for answers? Try searching our database.

Selecting exact number of row

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob - 22 Jul 2004 14:42 GMT
Hi there,

Here is another SQL related problem.  I have an application that
performs frequent searches.  One of the requirements is that it should
bring back an exact number of entities being searched no matter how
many describing rows there could be.  So for example: say you are
searching for customers and displaying customer orders.  Since
customers could have many orders doing SELECT TOP 100 would return not
100 customers but one hundred orders.  I see numerous alternatives
here: one, perform one SELECT that returns customers and then perform
100 SELECTs to return order for each customer.  Two, include a join in
the search SQL to a subquery that looks something like this:

SELECT custmers.name, orders.number
FROM customers join orders on customers.customer_id =
orders.customer_id
JOIN (select top 100 customer_id FORM customers WHERE customer.name =
'smith') AS top_customers ON customers.customer_id =
top_costumers.costumer_id

This approach presents its own problems like the redundant joins,
longer sql not to mention others.

Any thoughts?

Thanks

Bob
Adam Machanic - 22 Jul 2004 23:26 GMT
Do you have to bring back all of the orders for the 100 customers?  Or could
you, instead, bring back the most recent order for each of the 100 customers
and then provide drilldown funcationality to see other associated orders?

> Hi there,
>
[quoted text clipped - 8 lines]
> 100 SELECTs to return order for each customer.  Two, include a join in
> the search SQL to a subquery that looks something like this:
Bob - 23 Jul 2004 16:14 GMT
Actually I have to bring all the orders for all the customers.  That's
the root of the problem.

Thanks

Bob

> Do you have to bring back all of the orders for the 100 customers?  Or could
> you, instead, bring back the most recent order for each of the 100 customers
[quoted text clipped - 12 lines]
> > 100 SELECTs to return order for each customer.  Two, include a join in
> > the search SQL to a subquery that looks something like this:
Ed Prochak - 25 Jul 2004 21:01 GMT
> Actually I have to bring all the orders for all the customers.  That's
> the root of the problem.
[quoted text clipped - 19 lines]
>>>100 SELECTs to return order for each customer.  Two, include a join in
>>>the search SQL to a subquery that looks something like this:

then what does the "TOP 100" have to do with it? Sounds more like an ORDER BY
issue. Note that you can order by information not dosplayed in the SELECT.

Signature

Ed Prochak
running    http://www.faqs.org/faqs/running-faq/
netiquette http://www.psg.com/emily.html
--
"Two roads diverged in a wood and I
I took the one less travelled by
and that has made all the difference."
robert frost

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.