Hallo,
ich lese Einträge aus einer Tabelle wie folgt aus:
Erst kommen die Einträge mit...
1. alle top!=0 AND color=0 und status=expert
2. alle top=0 AND color!=0 und status=expert
3. alle top=0 AND color=0 und status=expert
4. alle status=basic
Tabelle:
id | top | color | type (basic, expert) | created on
1 | 1 | 0 | expert | 2009-01-05 15:54:26
2 | 2 | 0 | expert | 2009-01-06 15:54:26
3 | 3 | 0 | expert | 2009-01-04 15:54:26
4 | 2 | 0 | expert | 2009-01-06 15:54:26
5 | 0 | 0 | basic | 2009-01-07 15:54:26
5 | 0 | 1 | expert | 2009-01-16 15:54:26
6 | 0 | 0 | basic | 2009-01-09 15:54:26
7 | 0 | 2 | expert | 2009-01-12 15:54:26
8 | 0 | 0 | expert | 2009-01-06 15:54:26
9 | 0 | 1 | expert | 2009-01-08 15:54:26
10 | 0 | 3 | expert | 2009-01-04 15:54:26
11 | 0 | 2 | expert | 2009-01-03 15:54:26
12 | 0 | 0 | basic | 2009-01-08 15:54:26
13 | 0 | 1 | expert | 2009-01-06 15:54:26
Meine Query dazu:
(
SELECT *
FROM table
WHERE top!=0 AND color=0 AND type='expert' ORDER BY created_on DESC
UNION
(
SELECT *
FROM table
WHERE top=0 AND color!=0 AND type='expert' ORDER BY created_on ASC
)
UNION
(
SELECT *
FROM table
WHERE top=0 AND color=0 AND type='expert' ORDER BY created_on ASC
)
UNION
(
SELECT *
FROM table
WHERE type='basic' ORDER BY created_on ASC
)
LIMIT 0, 100
Leider funktioniert das nicht, da die Einträge nicht wie gewollt nach Datum (oder was anderem) sortiert werden...
Jemand eine Idee, wieso?
Danke,
gondor