![]() |
Datenbank: MySQL • Version: 5 • Zugriff über: PHP mysql_*()
MySQL: Bedingtes ORDER BY?
Hallo,
ich verstümmle ja ![]() Folgendes Statement:
SQL-Code:
Beim ORDER BY (ORDER BY t.topic_type DESC, t.topic_title ASC) würd ich jetzt gerne falls (t.forum_id = 1 OR t.forum_id = 2) das erste Ordnungskriterium komplett rausschmeissen. Geht das?
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2 WHERE t.forum_id = $forum_id AND t.topic_poster = u.user_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id AND t.topic_type <> " . POST_ANNOUNCE . " AND t.topic_title LIKE '$start_letter%' $limit_topics_time ORDER BY t.topic_type DESC, t.topic_title ASC LIMIT $start, ".$board_config['topics_per_page']; |
Re: MySQL: Bedingtes ORDER BY?
Nein.
|
Re: MySQL: Bedingtes ORDER BY?
Ok. :(
dann frickle ich halt ein bisschen mit PHP rum :mrgreen: EDIT: gibt es denn eine Möglichkeit, zwei Abfragen hintereinander zu klemmen? |
Re: MySQL: Bedingtes ORDER BY?
Ja, mittels UNION
SQL-Code:
SELECT Feld1, Feld2 FROM Abfrage2
UNION SELECT Feldx, Feldy From Abfrage2 |
Re: MySQL: Bedingtes ORDER BY?
hab ich dann pro SELECT ein eigenes ORDER BY?
|
Re: MySQL: Bedingtes ORDER BY?
Ja.
|
Re: MySQL: Bedingtes ORDER BY?
ok, danke. ich werde das mal ausprobieren, ich habs zwar jetzt mit php drin, aber das mach ich noch.
|
Re: MySQL: Bedingtes ORDER BY?
Zitat:
|
Re: MySQL: Bedingtes ORDER BY?
ja wie jetzt? Immer diese zwei-buchstaben-antworten :roll:
|
Re: MySQL: Bedingtes ORDER BY?
Zitat:
Im Ernst: Da Order by bei einem Union bezieht sich immer auf die gesamte Ergebnismenge... 2 Order by können also nicht angegeben werden, sondern ein Order by darf nur ganz zum Schluss stehen.. Edit: Eine Idee kommt mir aber noch, wie man das simulieren kann:
SQL-Code:
SELECT 1 as TableID, Feld1, Feld2 FROM Abfrage2
UNION SELECT 2 as TableID, Feld1, Feld2 From Abfrage2 order by 1, Feld1 Das order by 1 bewirkt dass nach der ersten Spalte sortiert wird. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:33 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 by Thomas Breitkreuz