473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Strange behavier in execution of this SQL query....

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
Nov 13 '05 #1
1 1290
On Mon, 11 Jul 2005 00:22:34 +0200, "Geir" <ge******@hotmail.com>
wrote:
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

Hi, how is the weather in Norway?
I can't answer your question as such but as no-one else has answered
yet maybe this is useful - it avoids using subqueries.

If you declared a table mynumbers (mynumber(PK)) of integers from 1 to
100 (say - the max number of matches in a season)

and you have a table
goals(player, matchnumber, season, goals)
with the first three fields the PK - this is the equivalent of your
table

and for convenience a query "scored" =
SELECT player, matchnumber, season FROM goals WHERE goals>0

then the query
SELECT season, player, mynumbers_1.mynum AS runlength, mynumbers.mynum
AS startmatch
FROM scored, mynumbers, mynumbers AS mynumbers_1
WHERE scored.matchnumber Between [mynumbers].[mynum] And
[mynumbers].[mynum]+[mynumbers_1].[mynum]-1
GROUP BY scored.season, scored.player, mynumbers_1.mynum,
mynumbers.mynum
HAVING mynumbers_1.mynum>1 AND
Count(scored.matchnumber)=[mynumbers_1].[mynum]

should give you you all the runs of consecutive scoring matches by
startmatch and player and runlength.
However, test it a bit!
HTH
David

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ethel Aardvark | last post by:
I am running a 9.0.1 database on a W2K server and have come across some strange behaviour with a SQL query. I have a query which runs in a PL/SQL cursor which has several PL/SQL variables used to...
4
by: Ryan | last post by:
Bit of an obscure one here, so please bear with me. I have two copies of a database which should be identical. Both have a complex view which is identical. I can open the views and the data is as...
4
by: Stefano | last post by:
Hi everibody, it's the first time i post on this newsgroup. I'm Stefano from Milano, italy. I'm a beginners with Sql2000. My problem is this. I run a View using enterprise manager and after less...
1
by: Vinny | last post by:
Can anyone help me with this strange problem please? I have a stored procedure, with a parameter defined as a uniqueidentifier. The procedure does a select with a number of joins, and filters...
24
by: LineVoltageHalogen | last post by:
Greetings All, I was hoping that someone out there has run into this issue before and can shed some light on it for me. I have a stored procedure that essentially does a mini ETL from a source...
6
by: Ryan | last post by:
I came across a situation that I've been unable to explain and was hoping somebody had an answer: I had written an update query which was taking about 8 seconds to run and considered it too...
1
by: Jeremy Jongsma | last post by:
I have a view, vw_tc_user_acccess, for determing user access to certain objects. On my machine, I get the following query execution times: 1. SELECT * FROM vw_tc_user_access: 33.04ms 2. SELECT...
0
by: ivb | last post by:
Hi all, I am using DB2 8.1.11.1 on NT with ASP.NET 1.1 When application make connection to database (via ADO.NET), it set "Connection timeout" parameter to 30 seconds. After, when my webpage...
3
by: Vish4u | last post by:
Hello Everyone, I have a encountered a strange issue with the execution of my stored procedure on clients machine. My stored procedure contains a cursor in which there is a select statement...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.