Abfrage über 2 Tabellen sortieren

Kahmoon

Erfahrenes Mitglied
Hi,

ich habe folgendes Scenario.

Table root54_artikel und root54_news.

Ich möchte in einem Menüpunkt "Blog" sowohl News als auch Artikel anzeigen...das ganze nach Datum sortiert. Irgendwie rieg ich keine Abfrage gebacken die mir die Datensätze aus beiden Tabellen nach Datum (erfasst) sortiert ausgibt sondern matscht es mir zusammen. Die Struktur der beiden Tabellen ist fast identisch.

Bisherige Abfrageversuche waren z.b.

SELECT root54_artikel.*, root54_news.* FROM root54_artikel, root54_news ORDER BY root54_artikel.erfasst AND root54_news.erfasst

Stehe leider total am Schlauch :(

Wäre dankbar für Tips

Gruß
Franky
 
Welches DBMS? ;-]
Gibt es eine Relation zwischen den beiden Tabellen? Wenn ja, dann schau mal in die vielen Threads zum Thema 'Abfragen über 2 Tabellen'.
Wenn nein und die Reihenfolge, Struktur usw. der zu selektierenden Spalten ist identisch, dann heißt Dein Zauberwort: z.B. UNION
für Oracle gilt:
:google:
The following examples combine the two query results with each of the set operators.

UNION Example
The following statement combines the results with the UNION operator, which eliminates duplicate selected rows. This statement shows that you must match datatype (using the TO_DATE and TO_NUMBER functions) when columns do not exist in one or the other table:

SELECT part, partnum, to_date(null) date_in
FROM orders_list1
UNION
SELECT part, to_number(null), date_in
FROM orders_list2;

PART PARTNUM DATE_IN
---------- ------- --------
SPARKPLUG 3323165
SPARKPLUG 10/24/98
FUEL PUMP 3323162
FUEL PUMP 12/24/99
TAILPIPE 1332999
TAILPIPE 01/01/01
CRANKSHAFT 9394991
CRANKSHAFT 09/12/02

SELECT part
FROM orders_list1
UNION
SELECT part
FROM orders_list2;

PART
----------
SPARKPLUG
FUEL PUMP
TAILPIPE
CRANKSHAFT


UNION ALL Example
The following statement combines the results with the UNION ALL operator, which does not eliminate duplicate selected rows:

SELECT part
FROM orders_list1
UNION ALL
SELECT part
FROM orders_list2;

PART
----------
SPARKPLUG
FUEL PUMP
FUEL PUMP
TAILPIPE
CRANKSHAFT
TAILPIPE
TAILPIPE


Note that the UNION operator returns only distinct rows that appear in either result, while the UNION ALL operator returns all rows. A part value that appears multiple times in either or both queries (such as 'FUEL PUMP') is returned only once by the UNION operator, but multiple times by the UNION ALL operator.

Es gibt dabei jedoch Probleme mit dem Sortieren. Falls du das doch brauchst erstellst Du dir zuerst eine View mit dem Select und diese kannst du anschließend mit einem Select ... from MeineView order by ... aufrufen.
mfg
 

Neue Beiträge

Zurück