×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Subquery

Subquery

(OP)
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?

RE: Subquery

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.

RE: Subquery

(OP)
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.

RE: Subquery

I would try;

CODE --> 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

RE: Subquery

(OP)
Thanks, that produces a result at least, but isn't selecting the top 3 Points for each date.



I'm wanting just from Simon C to James for this date.

RE: Subquery

"top 3 Points " for 04-May-19 would be: 37, 34, and 33, so you want "from Simon C to " Simon B, right ponder


---- Andy

There is a great need for a sarcasm font.

RE: Subquery

What is the primary key field in tblCumulativeScores?

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Subquery

(OP)
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.



RE: Subquery

You need a unique value/expression:

CODE --> sql

SELECT tblCumulativeScores.Player, tblCumulativeScores.CompDate, tblCumulativeScores.Points
FROM tblCumulativeScores
WHERE [unique value/expression] In
(SELECT TOP 3 [unique value/expression]
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close