473,385 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How To Select a Certain Limited Number of Rows Per ID

I have a table with entries tied to a membership database. The problem
is that I want to select a limit of sixteen entries per member, per
day, where some members have 16+ entries per day.

I have this so far ( which I've simplified for this post)

SELECT dbo.members.firstname, dbo.members.lastname,
dbo.entries.gameDay
FROM dbo.members INNER JOIN
dbo.entries ON dbo.members.memberID =
dbo.entries.memberID

If it's day 5, each member should have 80 total.

How can I change this to select only 16 entries for each member, making
sure it's 16 per day based on dbo.entries.gameDay?

Thanks for your help.

Sep 18 '06 #1
2 2179
Hello,

Post Table Schema and Sample entries in your table

M A Srinivas

un******@gmail.com wrote:
I have a table with entries tied to a membership database. The problem
is that I want to select a limit of sixteen entries per member, per
day, where some members have 16+ entries per day.

I have this so far ( which I've simplified for this post)

SELECT dbo.members.firstname, dbo.members.lastname,
dbo.entries.gameDay
FROM dbo.members INNER JOIN
dbo.entries ON dbo.members.memberID =
dbo.entries.memberID

If it's day 5, each member should have 80 total.

How can I change this to select only 16 entries for each member, making
sure it's 16 per day based on dbo.entries.gameDay?

Thanks for your help.
Sep 19 '06 #2

ma******@gmail.com wrote:
Hello,

Post Table Schema and Sample entries in your table

M A Srinivas

un******@gmail.com wrote:
I have a table with entries tied to a membership database. The problem
is that I want to select a limit of sixteen entries per member, per
day, where some members have 16+ entries per day.

I have this so far ( which I've simplified for this post)

SELECT dbo.members.firstname, dbo.members.lastname,
dbo.entries.gameDay
FROM dbo.members INNER JOIN
dbo.entries ON dbo.members.memberID =
dbo.entries.memberID

If it's day 5, each member should have 80 total.

How can I change this to select only 16 entries for each member, making
sure it's 16 per day based on dbo.entries.gameDay?

Thanks for your help.
I got a solution from another board, so I'll post it here.

create table members

(
memberID int identity,
firstname varchar(50),
lastname varchar(50)

)

create table entries

(
entryID int identity,
memberID int,
gameDay int
)

insert into members values('Joe', 'Smith')
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,1)
insert into entries values(1,2)
insert into entries values(1,2)
insert into entries values(1,2)
insert into entries values(1,2)
insert into entries values(1,2)

SELECT *
FROM Members m
INNER JOIN entries e
ON e.MemberID = m.MemberID
WHERE (SELECT COUNT(*)
FROM entries e2
WHERE e2.MemberID = e.MemberID
AND e2.GameDay = e.GameDay
AND e2.EntryID < e.EntryID
) < 16
Thanks

Sep 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: andy vandenberghe | last post by:
Hello everybody, i have the following table (agltransact), in which 2 fields are relevant: ex_inv_ref account 15 1512 15 6040 16 1512 16 1512 16 ...
1
by: Luc | last post by:
I am using Visual Studio 2003 and am getting lousy performance after using a datatable select and then trying to assign a value to a column of the row that was found: DataTable dt = new...
0
by: George | last post by:
Hi, The storeprocedure fails with null exception on the DB2 development centre for SELECT querys for all tables that has the number of columns greater than 10. Strange ,but true ..i reinstalled...
4
by: Simon Verona | last post by:
Normally Google is my friend, but I can't seem to work this one out. I'm sure it's really simple as well. I normally create a dataview from a table within a dataset using the ..defaultdataview...
0
by: SC | last post by:
I'm developing a site that may eventually have a very large database of users (hopefully, but who knows). Often there will be queries with multiple joins and sometimes may include a few fulltext...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
4
by: bizt | last post by:
Hi, I want to find an easy way to select only rows within a certain range when I do a select. Im sure I have seen this done with a SELECT statement but cant remember if or how it was done. Can...
1
by: bughunter | last post by:
simple query select * from "Result" res where (res."QID" = 51541 or res."QID" = 51542) works fine ("SRV-BL"."Result" ~ 900000 rows) and returns 36 rows but update - no! update...
2
by: BD | last post by:
Hi, all. My background is more Oracle than db2. My skills at SQL tuning are quite limited. I'm running 8.2 on Windows. I'm tasked with some SQL optimization, and am doing some explain plans...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.