473,385 Members | 1,907 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.

Picking out top three out of database

I have a database where I store info about football players goals. The
database contains the following:
GoalID, GoalScorerID, GoalMinute (which minute the goal was scored),
ClubID, FixtureID (to mark in which match the goal was scored) and
Penalty (which determines wether the goal was a penalty or not).

On the club page I want to show the top three goalscorers of the club.
I can do this but I donīt know how to get them in descending order
with the player whoīs scored most goals at the top of the list.

Any ideas?
Jul 22 '05 #1
9 1446
SELECT TOP 3
and
ORDER BY player DESC or ASC
Jul 22 '05 #2
On 8 Dec 2004 00:23:02 -0800, th***********@hotmail.com (Thomas)
wrote:
I have a database where I store info about football players goals. The
database contains the following:
GoalID, GoalScorerID, GoalMinute (which minute the goal was scored),
ClubID, FixtureID (to mark in which match the goal was scored) and
Penalty (which determines wether the goal was a penalty or not).

On the club page I want to show the top three goalscorers of the club.
I can do this but I donīt know how to get them in descending order
with the player whoīs scored most goals at the top of the list.

Any ideas?


Lots, some rather simple. Some may not apply to your database though.
If you tell us what database, we can suggest a solution.

(Hint: Check to see if your particular database supports the TOP
modifier in a SELECT statement...)

Jeff
Jul 22 '05 #3
Sorry for not answering earlier but itīs been a bit much to do.

The db used is Access. I have no clue if it supports the TOP modifier.
If not Access is to be used which db should I use. I need it to be free.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 22 '05 #4
Thomas Emilson wrote:
Sorry for not answering earlier but itīs been a bit much to do.

The db used is Access. I have no clue if it supports the TOP modifier.
If not Access is to be used which db should I use. I need it to be
free.

TOP works fine in Access. In the future, specify your database type and
version right at the start of your post so we dont' have to ask.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #5


Yeah, Iīll think of that next time around, but back to the thing here.

So how one use this TOP modifier?
Iīm not very good at sql so if anyone who feels they are would like to
explain this to me I would be grateful.

/Thomas

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 22 '05 #6
Thomas wrote:
Yeah, Iīll think of that next time around, but back to the thing here.

So how one use this TOP modifier?
Iīm not very good at sql so if anyone who feels they are would like to
explain this to me I would be grateful.

Well, Access DOES have online help. It also has a dandy Query Builder that
generates the SQL for you.
Basically, the syntax is
SELECT TOP x <column list> FROM <table/query>

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #7
It does support TOP

--
dlbjr
Pleading sagacious indoctrination!
Jul 22 '05 #8
Hi again Bob!

Iīve been at the online help for access and looked at the top modifier
but I couldnīt find out how it could help me.
It could only get the top posts of the recordset based on the value of
one of the columns.

But my problem is that I donīt have a column (or a table) that contains
the total goals scored. In my table 'Goalscorers' I have all the goals
that has been done and in which minute it was scored (and by which
player). Then I do a For... exit to find out how many times a playerid
is found in the table (which gives me the number of goals he has
scored).

The table looks like this:

GoalID | GoalScorerID | GoalMinute | ClubID | FixtureID
Hope this helps anything.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 22 '05 #9
Thomas wrote:
Hi again Bob!

Iīve been at the online help for access and looked at the top modifier
but I couldnīt find out how it could help me.
It could only get the top posts of the recordset based on the value of
one of the columns.

But my problem is that I donīt have a column (or a table) that
contains the total goals scored. In my table 'Goalscorers' I have all
the goals that has been done and in which minute it was scored (and
by which player). Then I do a For... exit to find out how many times
a playerid is found in the table (which gives me the number of goals
he has scored).

The table looks like this:

GoalID | GoalScorerID | GoalMinute | ClubID | FixtureID
Hope this helps anything.


So now you need to look up grouping and aggregate functions to, well, group
and aggregate the goals scored by each player.

SELECT TOP 3 GoalScorerID, Count(*) As TotalGoals
FROM GoalScorers
GROUP BY GoalScorerID
ORDER BY TotalGoals DESC

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #10

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

Similar topics

1
by: Thomas | last post by:
Sorry for not answering earlier... to much do at the moment, christmas time and all. The database used is an access, simply because I donīt know how to do with any other db. Would like to try...
1
by: NA | last post by:
Is it possible to have adjustable tables (not Access tables per se) but those in Ms Word or Excel based on nexted forms three deep? In other words, if I have a main form, Repair History, both the...
7
by: jballard | last post by:
Hello, I have a database set-up with a form and two subforms in it. I have one of the subforms (replacement parts) set-up where you can pick part numbers from a drop down box and also pick a...
46
by: RoSsIaCrIiLoIA | last post by:
Write a function that gets an array of unsigned int fill it with random values all differents, and sorts it. It should be faster than qsort too. Do you like my solution? _______________________...
1
by: discussions | last post by:
Hello all, I would like some advice how best to approach the following problem. I have "sort of" solved it but in a very horrible and complex way, I'm sure there's a better, simple and more...
5
by: kpp9c | last post by:
I have a several list of songs that i pick from, lets, say that there are 10 songs in each list and there are 2 lists. For a time i pick from my songs, but i only play a few of the songs in that...
5
by: Dwight | last post by:
Hi all, Iam a first time user of any database. I am using A2003. I want to design a database for county marriage records. So far, I have the following tables: COUNTY: County GROOM:...
6
by: John | last post by:
Hi I have three tables with a common id with which they can be linked. I need to merge them in a way that the resultant table has all records from three tables. Below is what sort of result I am...
2
by: zishiri | last post by:
Visual Basic6.0 Coding Help My Operating system is WindowsXP I am working on my current project in vb6.0. My problems are as follows. 1. I want a textbox of one form(form2) to pick a value to...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.