473,765 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(kampi d(PK),sesong, runde)
KampMaal((kampi d,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,pe rsid from KampFakta,KampM aal where sesong=2003 and
KampFakta.kampi d=KampMaal.kamp id) AS s1,
(Select sesong,runde,pe rsid from KampFakta,KampM aal where sesong=2003 and
KampFakta.kampi d=KampMaal.kamp id) 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 1314
On Mon, 11 Jul 2005 00:22:34 +0200, "Geir" <ge******@hotma il.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(kamp id(PK),sesong, runde)
KampMaal((kamp id,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,pe rsid from KampFakta,KampM aal where sesong=2003 and
KampFakta.kamp id=KampMaal.kam pid) AS s1,
(Select sesong,runde,pe rsid from KampFakta,KampM aal where sesong=2003 and
KampFakta.kamp id=KampMaal.kam pid) 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.myn um AS runlength, mynumbers.mynum
AS startmatch
FROM scored, mynumbers, mynumbers AS mynumbers_1
WHERE scored.matchnum ber Between [mynumbers].[mynum] And
[mynumbers].[mynum]+[mynumbers_1].[mynum]-1
GROUP BY scored.season, scored.player, mynumbers_1.myn um,
mynumbers.mynum
HAVING mynumbers_1.myn um>1 AND
Count(scored.ma tchnumber)=[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
2703
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 switch on and off certain rules. One idea I had was to have two queries UNIONed together with a simple switch selecting which half was to operate (I know it sounds like there are probably better ways of doing this but I have my reasons). To cut...
4
2354
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 expected and match. I can query it in several ways as detailed below. The 5th version of the simple query below based on the second copy of the view fails, but works under the first copy. /*1 Statement below works*/ SELECT * FROM AgentHierarchy
4
9744
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 then 20 second it goes in error time out. I run this view using a VB application and the error comes again .When i run it with Query Analyzer after 50 seconds it give me the right result. i've tried to change the value of querytimeout using...
1
2018
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 within the Where clause using this parameter. (@orderHeader_id uniqueidentifier) SELECT *
24
4750
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 OLTP DB to a the target Operational Data Store. This is still in development so both DB's reside on the same machine for convenience. The stored proc runs successfully from within Query analyzer and this holds true on the following platforms: XP...
6
4566
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 slow. I copied the SQL statement from the query and tried executing it from code which then ran in 1 second. To make sure that I didn't miss anything, I copied the SQL statement back into a query and tried running it again. It now also only took 1...
1
1860
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 * FROM vw_tc_user_access WHERE object_type = 'FORUM': 3.49ms 3. SELECT * FROM vw_tc_user_access WHERE object_type = 'CATEGORY': 107.53ms Queries #2 and #3 are obviously a subset of #1, simply filtered by object_type. My questions are:
0
3574
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 requests database, and query execution time exceeds 30 seconds, the following error reported: ===
3
1527
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 written in concatinated string format (provided below). when i execute the procedure on my clients database some concatinated lines in the select statement are not considered.(i.e the select statement is executed without those two line between the...
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9957
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8832
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.