ANSI SQL supports the TOP predicate. It works like this :
SELECT TOP 10 * FROM my_table;
-----Original Message-----
From: Richard Yee [mailto:[EMAIL PROTECTED]]
Sent: Saturday, December 18, 1999 10:07 AM
To: [EMAIL PROTECTED]
Subject: Re: OFF TOPIC: SQL
Giovanni,
In Oracle you can use the ROWNUM pseudo column to restrict the number of
records returned. I am not sure if this is supported in other databases.
ie. Select * from my_table where ROWNUM < 10;
This will return at most 10 rows.
Regards,
Richard.
============================================================================
====
Richard Yee
DMC1 Corporation
305 W. Evelyn Ave.
Mtn. View, CA. 94041
650-963-3116
[EMAIL PROTECTED]
============================================================================
====
-----Original Message-----
From: Giovanni Az�a Garc�a [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 17, 1999 12:38 PM
To: [EMAIL PROTECTED]
Subject: OFF TOPIC: SQL
Hello all,
I have worked a lot with SQL but I would like to know
how could I limit the number of rows one SELECT returns?
For example, if I had a table with Customers having for each
how much money they have spent in my company and I wanted to
know the 5 customers that have spent the most, *ONLY* five:
SELECT *
FROM CUSTOMER_TABLE
ORDER BY MONEY_SPENT; // This would return all rows ordered
How could I limit this using SQL specifying the ammount of rows in advance?
I mean without having to iterate over all existing records.
The only approach I have found is using the HAVING option so I could say
HAVING MONEY_SPENT > X but how can I determine a X for that there
are only Y records.
Thanks in advance,
Giovanni
PD: Maybe I'm expecting too much from SQL
BCs. Giovanni Az�a Garc�a
Bachelor in Computer Science
Banking and Economic Information Center
Central Bank of Cuba
ICQ# 20725388
e-mail: [EMAIL PROTECTED]
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html