![]() |
Re: [MYSQL] Letzte Einträge pro kategorie
Brrrr.... Ich Depp hab ja auch einfach das group by verduselt:
SQL-Code:
gibt dann Folgendes aus:
SELECT cat_id, max (image_date) as last_image_date
FROM 4images_images group by cat_id
Code:
1 2
2 12 5 6 6 20 |
Re: [MYSQL] Letzte Einträge pro kategorie
Siehste, das ist Schritt 1. Wenn dann noch gejoint werden muss, wird es etwas kniffliger. Aber hast schon Recht, so isses IMHO richtig.
|
Re: [MYSQL] Letzte Einträge pro kategorie
Ich sag ja... Habs nur verschwitzt :wall:
|
Re: [MYSQL] Letzte Einträge pro kategorie
Schön, dass wir uns schlussendlich doch einig geworden sind, oder? :thumb:
|
Re: [MYSQL] Letzte Einträge pro kategorie
Darauf mach ich mir doch glatt mal nen Wein auf. :wink:
|
Re: [MYSQL] Letzte Einträge pro kategorie
erstmal danke für eure Antworten...
der Link von DeddyH hat mir schon geholfen (auch wenns Arg kompliziert in meinen Augen ist...) jellys link gibt mir leider nur die benannten spalten an, und lässt kein * zu... meine aktuelle Abfrage sieht so aus:
SQL-Code:
jetzt hatte ich probiert mir den Kategoriename aus einer anderen Tabelle zu holen. normal geht das ja so:
SELECT * FROM 4images_images i2 WHERE i2.image_date = (SELECT MAX(i1.image_date) AS neustes FROM 4images_images i1 WHERE i1.cat_id = i2.cat_id);
SQL-Code:
meine bisherigen versuche, dies in mein aktuelles set einzubauen werden, bringt mir mehr resultsets als ursprünglich, statt nur den name oder einen Mysql-Fehler durch die variablenzuweisung (i2). mal einer der vielen versuche:
SELECT * , 4images_categories.cat_name AS catname FROM 4images_images,4images_categories WHERE 4images_categories.cat_id = 4images_images.cat_id
SQL-Code:
Gruß Frank
SELECT * FROM , 4images_categories.cat_name AS catname
FROM 4images_images i2 ,4images_categories WHERE (4images_categories.cat_id = 4images_images.cat_id) and (i2.image_date = (SELECT MAX(i1.image_date) AS neustes FROM 4images_images i1 WHERE i1.cat_id = i2.cat_id) ); |
Re: [MYSQL] Letzte Einträge pro kategorie
Mal schnell heruntergetippt:
SQL-Code:
So sollte es richtig sein. Wenn nicht, bitte nochmal melden.
SELECT A.*,B.cat_name AS catname
FROM 4images_images A JOIN 4images_categories B ON B.cat_id = A.cat_id WHERE A.image_date = ( SELECT MAX(C.image_date) FROM 4images_images C WHERE C.cat_id = A.cat_id) |
Re: [MYSQL] Letzte Einträge pro kategorie
danke dir deddyH,
funktioniert wie es soll...jetzt mus ich mich da nur reindenken ;), aber dazu gibts ja genug doku... Gruß Frank |
Re: [MYSQL] Letzte Einträge pro kategorie
Vielleicht ist es besser zu verstehen, wenn man es etwas umformuliert:
SQL-Code:
SELECT A.*,B.cat_name AS catname
FROM 4images_images A, 4images_categories B WHERE B.cat_id = A.cat_id AND A.image_date = ( SELECT MAX(C.image_date) FROM 4images_images C WHERE C.cat_id = A.cat_id) |
Re: [MYSQL] Letzte Einträge pro kategorie
Was spricht gegen:
SQL-Code:
Warum also mit SubSelects arbeiten, was die Abfrage bestimmt nicht schneller macht.
select
B.cat_id, B.cat_name, max(A.image_date) as Max_image_date from 4images_images A inner join 4images_categories B on B.cat_id = A.cat_id group by B.cat_id, B.cat_name |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:17 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz