Results 1 to 3 of 3

Thread: SQL: Subquery met beperkt aantal records

  1. #1
    Delphi & OO in Vlaanderen SamWitse's Avatar
    Join Date
    Sep 2007
    Location
    Brussel
    Posts
    833

    Question SQL: Subquery met beperkt aantal records

    Beste forumidabele leden,

    Dit is -vrees ik- een Interbase-specifieke vraag.
    Ik wil de eerste rij van een zeer zware join.

    SQL Code:
    1. SELECT * FROM tabel1 LEFT JOIN tabel2 ON (tabel1.veld = tabel2.id) ROWS 1

    Ik dacht deze query te versnellen door eerst het eerste record te nemen van tabel1, en dan pas de JOIN uit te voeren:
    SQL Code:
    1. SELECT * FROM tabel1 LEFT JOIN tabel2 ON (tabel1.veld = tabel2.id) WHERE tabel1.id = (SELECT ID FROM tabel1 ROWS 1)

    Helaas zegt interbase dat ik geen ROWS in deze tweede query mag gebruiken (invalid token).
    Ter info: in de eerste query mag ik wel ROWS gebruiken (dit is de syntax van Interbase om het eerste record te krijgen).

    Weet iemand een oplossing?
    Last edited by SamWitse; 08-Sep-11 at 12:12.
    Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration.

    Sam Witse.
    Delphi & OO in Vlaanderen

  2. #2
    Dit werkt vast wel (tenminste, in Firebird):

    Code:
    SELECT * 
    FROM tabel1 
    LEFT JOIN tabel2 
    ON (tabel1.veld = tabel2.id) 
    WHERE tabel1.id = (SELECT FIRST 1 ID FROM tabel1)

  3. #3
    Delphi & OO in Vlaanderen SamWitse's Avatar
    Join Date
    Sep 2007
    Location
    Brussel
    Posts
    833
    Bedankt voor de test, Fanta.
    Blijkt dus een GrrrrrrrrInterbase-beperking te zijn.

    Mijn performatieprobleem is ondertussen wel al opgelost.
    Gewoon ter info:

    SQL Code:
    1. SELECT * FROM tabel1 JOIN tabel2 JOIN tabel3 ON (tabel1.veld1=tabel2.id) ON (tabel2.veld2=tabel3.id)

    is dus NIET hetzelfde als

    SQL Code:
    1. SELECT * FROM tabel1 JOIN tabel2 ON (tabel1.veld1=tabel2.id) JOIN tabel3 ON (tabel2.veld2=tabel3.id)
    (let op de plaatsing van de ON...)
    Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration.

    Sam Witse.
    Delphi & OO in Vlaanderen

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •