Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

Selecting X number of records out of Y

Hi,

I want to select X number of records out of Y number of records.
How do i do that ?

i.e. suppose I have 100 records(Y)
I want to select 50 records(X)  out of these 100 records
How do I do that ? And if I want to select 50% (or 20%), how do I do that ?

Is it different in DAO/ADO ?

select X...? I have no clue

Thanks.
0
aftab2003
Asked:
aftab2003
1 Solution
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Depends on the database you're using, but typically in MS SQL and Access, it would be "SELECT TOP x * FROM Table"

But I'm not sure if that would work with %'s.  It definitely works for a specific number of records, like if you wanted the top 3 records, you'd say SELECT TOP 3 * FROM Table
0
 
david_barkerCommented:
For the percentages :
    SELECT TOP 20 PERCENT * FROM Table
or SELECT TOP 50 PERCENT * FROM Table
0
 
jkwassonCommented:
you can also do this...

select count(*) as recordcount from tablea where recordcount = 50

would return the first 50 records from tablea

jk
0
 
leonstrykerCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:

Answered leew (13635347)

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

leonstryker
EE Cleanup Volunteer
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now