SQL fails
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #1
SQL fails
I'm trying to fetch the most popular threads to show them in the portal, this is the query I have:

SQL Code
1
2
3
4
5
6
SELECT t.subject, t.tid, t.views, t.icon, t.prefix
                         FROM ".TABLE_PREFIX."threads t
                         LEFT JOIN ".TABLE_PREFIX."ratemf_log l ON (l.pid=t.firstpost)
                         WHERE t.visible='1' {$overview_unviewwhere} AND t.closed NOT LIKE 'moved|%'
                         ORDER BY t.views DESC
                         LIMIT 0, {$settings['overview_max']};


As you can see, I'm joining a different tables to order the threads by the number of "rates" the thread has had. In the above I just joined, the query still works as usual. The problem comes here:

SQL Code
1
2
3
4
5
6
SELECT t.subject, t.tid, t.views, t.icon, t.prefix, COUNT(l.uid) AS logs
                         FROM ".TABLE_PREFIX."threads t
                         LEFT JOIN ".TABLE_PREFIX."ratemf_log l ON (l.pid=t.firstpost)
                         WHERE t.visible='1' {$overview_unviewwhere} AND t.closed NOT LIKE 'moved|%'
                         ORDER BY t.views DESC
                         LIMIT 0, {$settings['overview_max']};


I added:

SQL Code
, COUNT(l.uid) AS logs
, COUNT(l.pid) AS logs
, COUNT(l.lid) AS logs


That is suppose to count the number of rows for that thread, but that alone shouldn't affect the query at all, just that it does, the thread being pulled are no the same as the one before adding that piece of code.

This doesn't seem to work either.

SQL Code
, COUNT(l.*) AS logs


But ", l.lid", ", l.*", or ", l.pid" does Erf

Any clue?


Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
08-22-2012 09:13 AM
Visit this user's website Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
SQL fails - Sama34 - 08-22-2012 09:13 AM
RE: SQL fails - ZiNgA BuRgA - 08-22-2012, 10:36 AM
RE: SQL fails - Sama34 - 08-22-2012, 12:59 PM
RE: SQL fails - ZiNgA BuRgA - 08-22-2012, 02:13 PM
RE: SQL fails - Sama34 - 08-22-2012, 06:22 PM
RE: SQL fails - ZiNgA BuRgA - 08-23-2012, 08:32 AM
RE: SQL fails - Sama34 - 08-25-2012, 04:24 AM
RE: SQL fails - ZiNgA BuRgA - 08-25-2012, 11:30 AM
RE: SQL fails - Sama34 - 08-25-2012, 04:52 PM

 Standard Tools
Forum Jump: