Solved

how to select the top x number of records

Posted on 2003-10-23
5
185 Views
Last Modified: 2013-12-24
if i have a field name called points in a table named blah, how do i write the query so that
it will select the top 40 records that have the most points, putting them in the correct order from highest to least?
0
Comment
Question by:sagardeo
5 Comments
 
LVL 6

Accepted Solution

by:
PE_CF_DEV earned 325 total points
ID: 9606889
<cfquery name="blah" datasource="somewhere" maxrows=40>
Select *, points
from table
ORDER BY points DESC
</cfquery>
0
 
LVL 9

Assisted Solution

by:CFDevHead
CFDevHead earned 25 total points
ID: 9606896
This should work for what you are trying to do
Select top 40 points from points_table order by points DESC

Hope this helps.
0
 
LVL 17

Assisted Solution

by:anandkp
anandkp earned 50 total points
ID: 9608844
in ORACLE i wld use

select points from (Select points from points_table order by points DESC) where rownum <= 40

K'Rgds
Anand
0
 
LVL 10

Assisted Solution

by:Mause
Mause earned 50 total points
ID: 9609070
And for microsoft access:

<cfquery name="QUERYNAME" datasource="#DATASOURCE#">
         SELECT points
         FROM points_table
         ORDER BY points DESC
         LIMIT 40
</cfquery>

Mause
0
 
LVL 5

Assisted Solution

by:jayeshshah
jayeshshah earned 50 total points
ID: 9609430
in Ms-Access or Ms-SQL you can write the query as

SELECT top 40 * FROM points_table order by points table;


K'Regards

Jayesh
0

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Apache SSL and mod_rewrite not working 8 223
assigning port numbers to web sites and web services 2 83
AWS Advice on using WHM/cPanel 1 87
setup wamp server for first time 2 99
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question