Solved

how to select the top x number of records

Posted on 2003-10-23
5
152 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now