phpbar.de logo

Mailinglisten-Archive

[php] [etwas OT] DB-Zeilen "filtern"

[php] [etwas OT] DB-Zeilen "filtern"

Kristian =?iso-8859-1?Q?K=F6hntopp?= kk_(at)_netuse.de
Wed, 21 Jul 1999 14:42:43 +0200


Kristian Köhntopp wrote:
> select * from doc
>   where id  = ( select id from doc group by id )
>     and ver = ( select max(ver) from doc group by id);

Das ist so falsch. In Oracle:

SQL> desc doc;
 Name                            Null?    Type
 ------------------------------- -------- ----
 ID                              NOT NULL NUMBER(38)
 VER                             NOT NULL NUMBER(38)
 DATEN                           NOT NULL VARCHAR2(127)

SQL> select * from doc;

        ID        VER
---------- ----------
DATEN
--------------------------------------------------------------------------------
         1          1
doc 1 ver 1

         1          2
doc 1 ver 2

         2         10
doc 2 ver 10

         2         15
doc 2 ver 15


Und dann muß die Subquery so aussehen:

SQL> select * from doc where ( id, ver ) in ( select id, max(ver) from doc group
 by id);

        ID        VER
---------- ----------
DATEN
--------------------------------------------------------------------------------
         1          2
doc 1 ver 2

         2         15
doc 2 ver 15


Darum will man statt MySQL eine richtige Datenbank verwenden...

Kristian

-- 
Kristian Köhntopp, NetUSE Kommunikationstechnologie GmbH
Siemenswall, D-24107 Kiel, Germany, +49 431 386 436 00
Using PHP3? See our web development library at
http://phplib.shonline.de/ (GPL)


php::bar PHP Wiki   -   Listenarchive