MyBB Hacks

Full Version: Limit SQL query by users
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

SQL Code
				$query = $db->query('
					SELECT a.aid, a.name, a.image, p.uid
					FROM '.TABLE_PREFIX.'ougc_awards a
					JOIN '.TABLE_PREFIX.'ougc_awards_users ag ON (ag.aid=a.aid)
					JOIN '.TABLE_PREFIX.'posts p ON (p.uid=ag.uid)
					WHERE p.'.$pids.' AND a.visible=\'1\' AND a.type!=\'1\'
					ORDER BY ag.date desc'
				);


i want to limit the number of rows by UID, how?

xD

Now seriously, I have no idea. Some clue please?

???
You mean limit the number of results the above query can return for each distinct uid?  No other limits whatsoever?
Basically, you want the latest things for each user?

If it's one uid, it can be done (use GROUP BY clause).  More than one is a difficult thing to accommodate with SQL.
http://stackoverflow.com/questions/15376...http://stackoverflow.com/questions/1537606/mysql-group-by-with-top-n-number-of (see 2nd answer)
Yes that is what I mean, limiting by UID and not as a general limit. Looking at the code seems like a complex query.

Thanks.
Do you think a query similar to that will significantly affect performance in threads?
Follow the link in the answer - there's some discussion on that.
Probably not much, but I'd trust his investigation more than my intuition.
Reference URL's