Code:
SQL query:
SELECT thread. * , post. * , IF( thread.pollid = poll.pollid, 'poll.*', '' )
FROM forum_thread AS thread
LEFT JOIN forum_post AS post ON ( post.postid = thread.firstpostid ) IF( thread.pollid = poll.pollid, 'LEFT JOIN forum_poll AS poll ON (poll.pollid = thread.pollid)', '' )
WHERE thread.forumid =2
LIMIT 0 , 30
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF( thread . pollid = poll . pollid , 'LEFT JOIN forum_poll AS poll ON (poll.pol' at line 1
Removed the entire poll table check from the query. All I need is to check if a poll exists anyway, which can be done with thread.pollid
Was returning NULL because I somehow deleted every record in my post table. Good thing I made a backup yesterday.
Now the query works as expected:
Code:
SELECT thread.*, post.*
FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = thread.firstpostid)
WHERE thread.forumid = " . $forumid . "