phpbar.de logo

Mailinglisten-Archive

[php] wie sortieren?

[php] wie sortieren?

Kristian =?iso-8859-1?Q?K=F6hntopp?= kk_(at)_netuse.de
Tue, 06 Jul 1999 10:13:46 +0200


Michael Renner wrote:
> aus zwei (!) Datenbankabfragen erhalte ich zwei Arrays
> die ich in der cronologisch richtigen Reihenfolge anzeigen
> will.

UNION Operator in SQL?

kk_(at)_land:~ > sqlplus

SQL*Plus: Release 8.0.5.0.0 - Production on Tue Jul 6 10:4:59 1999

(c) Copyright 1998 Oracle Corporation.  All rights reserved.

Enter user-name: kris
Enter password:

Connected to:
Oracle8 Release 8.0.5.0.0 - Production
PL/SQL Release 8.0.5.0.0 - Production

SQL> describe q1;
 Name                            Null?    Type
 ------------------------------- -------- ----
 I                                        NUMBER(38)
 J                                        NUMBER(38)
 K                                        NUMBER(38)

SQL> describe q2;
 Name                            Null?    Type
 ------------------------------- -------- ----
 I                                        NUMBER(38)
 J                                        NUMBER(38)
 K                                        NUMBER(38)

SQL> select * from q1;

         I          J          K
---------- ---------- ----------
         1          2          3
         4          5          6
        10         11         12

SQL> select * from q2;

         I          J          K
---------- ---------- ----------
         5          6          7
         2          3          4
        20         20         20

SQL> select i, j, k from q1 union select i, j, k from q2 order by i;

         I          J          K
---------- ---------- ----------
         1          2          3
         2          3          4
         4          5          6
         5          6          7
        10         11         12
        20         20         20

6 rows selected.

Jedoch:

mysql> select i, j, k from q1 union select i, j, k from q2;
ERROR 1064: You have an error in your SQL syntax near 'select i, j, k from q2' at line 1

Mysql ist zu blöd für so etwas. Da muß dann der manuelle Merge-Sort her.

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