Solved

how to select the top x number of records

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
json_decode return null? 8 87
Domain Name E-mail Address & Outlook Integration 3 42
How to redirect https://www to non-www? 6 75
AWS Advice on using WHM/cPanel 1 75
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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