Hi,
I'm making a SQL query that shall return which players that have made
soccergoals in most games in a row in the same season.
Tables:
KampFakta(kampid(PK),sesong, runde)
KampMaal((kampid,maalnr)(PK), persid)
The Sql query looks like this:
SELECT s1.persid, s1.sesong, s1.runde AS forste, s2.runde AS siste,
(s2.runde - s1.runde + 1) AS antall
FROM
(Select sesong,runde,persid from KampFakta,KampMaal where sesong=2003 and
KampFakta.kampid=KampMaal.kampid) AS s1,
(Select sesong,runde,persid from KampFakta,KampMaal where sesong=2003 and
KampFakta.kampid=KampMaal.kampid) AS s2
WHERE s2.sesong = s1.sesong
AND s2.persid = s1.persid
AND s2.runde > s1.runde
AND not exists (SELECT runde
FROM KampFakta AS k
WHERE k.sesong = s1.sesong
AND k.runde > s1.runde
AND k.runde < s2.runde
AND not exists (SELECT *
FROM KampMaal
WHERE kampid =
k.kampid
AND persid =
s1.persid));
This SQL only returns players that have scored in 2 games in a row. While i
have players registered with at least 4 games in a row with goals.
When i run the same SQL query in Postgresql i get the right result.
It's something to do with the "NOT EXISTS" blocks. If i leave out that part
it all looks good at that stage in the query.
Any ideas why this query clearly is interpreted different in MS-Access /
Postgresql ?
Or why it does not work at all ?
Regards,
Geir
Norway