View Single Post
Old 01-18-2005, 03:53 AM   #7 (permalink)
littlebighead
Upright
 
Location: Berkeley, CA
Quote:
Originally Posted by welshbyte
Well i originally posted a big thank you here but the SQL query i came up with just seemed to work because the last 5 posts in my forum were all from different topics. Here's what i'm dealing with now:
...
A couple things I noticed that puzzled me:
1. Your query groups by p.post_topic, yet you are still selecting from other columns that are not aggregated (with max, min, etc.). This seems like a SQL syntax violation -- all columns in the SELECT clause that are not aggregated should appear in the GROUP BY clause.
2. LEFT JOINs can be expensive, and if you can get away without having to use them, your query will run faster. So, in this case, if p.post_topic is NEVER NULL, then the LEFT JOIN with t is wasted and should be converted into an INNER JOIN. Similar cases with the other LEFT JOINs.
littlebighead is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76