Union mellem to tabeller
Jeg er ved at kode et forum, og har derfor brug for at lave en union mellem 2 tabeller. Jeg har styr på union'en, og det virker også (næsten).Problemet er at jeg har mine "threads" i en tabel og mine "replies" i en anden. Jeg vil så gerne vise mine "threads" sorteret efter datoerne i mine 2 tabeller, men når jeg forsøger at gøre det med en union, bliver mine "threads" vist for hver gang der er et "reply", og det vil jeg gerne undgå.
Her kommer min SQL-streng.
(SELECT DISTINCT forum_threads.id,forum_threads.addeddate,CONCAT(firstname,' \"',username,'\" ',lastname) AS name,forum_threads.header FROM forum_threads LEFT JOIN members ON forum_threads.author = members.id WHERE foraid = " + intFid + ")
UNION
(SELECT DISTINCT forum_threads.id,forum_replies.addeddate,CONCAT(firstname,' \"',username,'\" ',lastname) AS name,forum_threads.header FROM forum_replies INNER JOIN forum_threads ON threadid = forum_threads.id LEFT JOIN members ON forum_threads.author = members.id WHERE foraid = " + intFid + ") ORDER BY addeddate DESC;