Limit SQL query by users
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #1
Limit SQL query by users

SQL Code
1
2
3
4
5
6
7
8
				$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?


Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
12-14-2012 06:36 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: Limit SQL query by users
???
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)

My Blog
(This post was last modified: 12-19-2012 10:01 PM by ZiNgA BuRgA.)
12-14-2012 09:19 PM
Find all posts by this user Quote this message in a reply
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #3
RE: Limit SQL query by users
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.

Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
(This post was last modified: 12-18-2012 12:23 PM by Sama34.)
12-18-2012 12:23 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #4
RE: Limit SQL query by users
Do you think a query similar to that will significantly affect performance in threads?

Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
12-19-2012 06:16 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #5
RE: Limit SQL query by users
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.

My Blog
(This post was last modified: 12-19-2012 10:03 PM by ZiNgA BuRgA.)
12-19-2012 10:02 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: