DiBo33: Ist diese Abfrage überhaupt möglich?

Beitrag lesen

#favorit_favorites
listid catordiscid catordisc(1=Kategorie, 2=Diskussion)
1 1 1
2 95 2
1 22 1

#board_category
categoryid categoryname
1 "Foo"
22 "Bar"

#board_thread
threadid threadtitel
95 "Eine Diskussion"

Mal auf diese 3 konzentriert

Ich möchte nun gerne:
-> "Foo"
-> "Bar"
-> "Eine Diskussion"

Dann wäre ein Ansatz in etwa so:

[code=sql]
SELECT CASE WHEN t1.catordisc = 1 THEN t2.categoryname ELSE t3.threadtitel END AS beste_diskussion
FROM favorit_favotites AS t1
JOIN board_category AS t2 ON t1.catordiscid = t2.categoryid
JOIN board_thread AS t3 ON t1.catordiscid = t3.threadid
[/code]