Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subquery

Status
Not open for further replies.

TrekBiker

Technical User
Nov 26, 2010
330
GB
This query is giving error 'Query input must contain at least one table'.

Code:
SELECT tblCumulativeScores.Player, tblCumulativeScores.CompDate, tblCumulativeScores.Points
(SELECT TOP 3 tblCumulativeScores.Points
FROM tblCumulativeScores as Dupe
WHERE (((Dupe.CompDate)=tblCumulativeScores.CompDate))
ORDER BY tblCumulativeScores.Points DESC);

Why is this?
 
I does not look a valid SQL statement, I think you are missing a FROM after the tblCumulativeScores.Points, but something else is still missing.
 
Thanks for response.
What I'm trying to do is extract from tblCumulativeScores the top 3 placings, with ties, for each CompDate.
Clearly struggling to make it work, so alternative approaches welcomed.
 
I would try;

SQL:
SELECT tblCumulativeScores.Player, tblCumulativeScores.CompDate, tblCumulativeScores.Points
FROM tblCumulativeScores
WHERE tblCumulativeScores.Points In
(SELECT TOP 3 tblCumulativeScores.Points
FROM tblCumulativeScores as Dupe
WHERE Dupe.CompDate=tblCumulativeScores.CompDate
ORDER BY tblCumulativeScores.Points DESC);

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Thanks, that produces a result at least, but isn't selecting the top 3 Points for each date.

Duane_yrvq5g.jpg


I'm wanting just from Simon C to James for this date.
 
top 3 Points " for 04-May-19 would be: 37, 34, and 33, so you want "from Simon C to " Simon B, right [ponder]

Simon1_pukaew.png



---- Andy

There is a great need for a sarcasm font.
 
Andrzejek, I want the top 3 places, including ties, so not top 3 Points. In the example Simon C and Danie were in joint first place, and Andy, Lance and James were in joint third.

Duane,tblCumulativeScores is fed by an append query based on data in a form that does a number of calculations to arrive at a points score for each player taking part on a CompDate for an event with a RoundID, which is an Autonumber / Primary Key obtained from a tblRound.

This will sound confusing but tblCumulativeScores doesn't have its own Primary Key, since unique records are being appended into it. From tblCumulativeScores I want to find out who was first, second and third on each date.



 
You need a unique value/expression:

SQL:
SELECT tblCumulativeScores.Player, tblCumulativeScores.CompDate, tblCumulativeScores.Points
FROM tblCumulativeScores
WHERE [highlight #FCE94F][unique value/expression][/highlight] In
(SELECT TOP 3 [highlight #FCE94F][unique value/expression][/highlight]
FROM tblCumulativeScores as Dupe
WHERE Dupe.CompDate=tblCumulativeScores.CompDate
ORDER BY tblCumulativeScores.Points DESC);

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top