MySQL Forums
Forum List  »  Newbie

Re: SELECT TOP 3 scores in each class with JOIN
Posted by: Peter Brawley
Date: October 04, 2016 08:33PM

> Excellent

You're welcome.

> however, there still has to be a join or union.

You don't say!

The principle for writing the exclusion set (in the parenthesised expression aliased as d) is to write it first as a self-standing query of the form ...

select x.class, x.entrynum, x.score, y.active, y.dsq
from hwdata x
left join awards y on x.award=y.award
                  and y.active = 1
                  and y.dsq != 1     -- or whatever ...
        where y.id is null;

I don't have time today to finish and test this in detail not least because looking at your row criterion lists, I see no way to translate them into SQL that works with these tables. The data structure appears not to support them; tables will need to be changed. It's been a problem from the beginning. I may be mistaken about it, but it'd take more time than I have to find out. IAC as above it's your job.

A workaround would be to manually assemble eligible rows to a temp table, and run the Top 3 query on that.

Quote

(I have an entire program made for this and changing every column name to all lowercase is not time essential. Plus I like the way it looks to me so I'll keep the case structure)

A basic aspect of DB development is to write and test all required queries before application code is written---because that process most always exposes problems that need DB design changes. It appears you're facing that now.

Options: ReplyQuote


Subject
Written By
Posted
Re: SELECT TOP 3 scores in each class with JOIN
October 04, 2016 08:33PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.