Re: SUM problem.
Peter,
I've read the manual about JOINs but the thing is, I don't understand it :(
I understand the SELECT you made where I get the deltagare and points and only 2 highest scores, that part I understand why and it makes perfect sence to me.
My problem however is that I need information from all 3 of my tables in order to sort it correctly (atleast I think I do).
Why I need info from lepok_anvandare is because I need the name of the persons with the 'deltagare' id (lepok_anvandare.id = lepok_resultat.deltagare).
I allso need the info from lepok_turnering (as the type of torney is saved there, and I only want the result from the torneys saved with the key "typ=pligan" and I need the year from when the torney was played so it only shows the result from the current years torneys and not add old ones)
In the code you wrote :
SELECT a.deltagare, a.poang, count(*) AS higher
FROM lepok_resultat a
JOIN lepok_resultat b ON a.deltagare=b.deltagare AND a.poang <= b.poang
GROUP BY a.deltagare, a.poang
HAVING higher <= 2
ORDER BY a.deltagare,higher ;
Changeing the last line to
ORDER BY SUM(a.poang);
And then printing SUM(a.poang) would that only SUM the 2 top results or would it SUM all 3?
That I change the ORDER BY is just so that the one with the highest SUM should be printed first.
And btw, is there a jawa script engine (or similar) on this site (or other site) where you could just input the CREATE TABLE that I printed in the earlier post to try out different SELECTs ? (trial and error ftw :P)
So the quests this time...
1) Can you get information from 3 different tables but only join 1 of em ?
2) In above example, SUM(a.poang) would it only calculate the top 2 results or would it actually calculate all 3 ?
3) Does a easy web based plugin to test code exist?
I think that's all for right now, and sorry for being such a pain in the ass and asking stupied questions, but I'm trying to understand this and I really appriciate (spelling) your help :)