Tag: SQL
SQL Headache?
by Eric on Mar.09, 2010, under work
I thought I had a headache, today, and then I came across an SQL problem. Actually, it was just a crashed table, but the SQL in the error message made my head spin...
SELECT IF(votenum >= 1, votenum, 0) AS votenum, IF(votenum >= 1 AND votenum > 0, votetotal / votenum, 0) AS voteavg, post.pagetext AS preview, thread.threadid, thread.title AS threadtitle, thread.forumid, pollid, open, postusername, postuserid, thread.iconid AS threadiconid, thread.dateline, notes, thread.visible, sticky, votetotal, thread.attach, thread.lastpost, thread.lastposter, thread.lastpostid, thread.replycount, IF(thread.views<=thread.replycount, thread.replycount+1, thread.views) AS views, thread.prefixid, thread.taglist, hiddencount, deletedcount , NOT ISNULL(subscribethread.subscribethreadid) AS issubscribed , deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason, threadredirect.expires, post.pagetext AS previewbbcode FROM thread AS thread LEFT JOIN deletionlog AS deletionlog ON(thread.threadid = deletionlog.primaryid AND deletionlog.type = 'thread') LEFT JOIN subscribethread AS subscribethread ON(subscribethread.threadid = thread.threadid AND subscribethread.userid = 1682 AND canview = 1) LEFT JOIN post AS post ON(post.postid = thread.firstpostid) LEFT JOIN threadredirect AS threadredirect ON(thread.open = 10 AND thread.threadid = threadredirect.threadid) WHERE thread.threadid IN (0,25887,23738,25882,25869,25881,25843,25792,25533,24533,25874,25879,25884,25870,25866,25873,25832,25846,22121,15123,25859) ORDER BY sticky DESC, lastpost DESC;
....After that? I need a drink...
Related articles by Zemanta
- How to Copy or Move MS SQL Database (crazzycool.blogspot.com)
- SQL 10+ tips for working smarter (domainmacher.com)
- Conditional Joins in MySQL (scvinodkumar.wordpress.com)





