Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id B255E1337B56 for ; Sun, 5 Dec 2010 12:59:15 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 69806-03 for ; Sun, 5 Dec 2010 16:59:08 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from out.mail.amis.hr (out1.mail.amis.hr [188.129.0.4]) by mail.postgresql.org (Postfix) with ESMTP id 75FB31337B50 for ; Sun, 5 Dec 2010 12:59:08 -0400 (AST) Received: from out.fsec.sm.srv.amis.hr (out.fsec.sm.srv.amis.hr [192.168.106.22]) by out.mail.amis.hr (Postfix) with ESMTP id BFDE41FFEE for ; Sun, 5 Dec 2010 17:59:07 +0100 (CET) Received: from pps.filterd (out [127.0.0.1]) by out.fsec.sm.srv.amis.hr (8.14.3/8.14.3) with SMTP id oB5Gv3Hv023844 for ; Sun, 5 Dec 2010 17:59:07 +0100 Received: from smtp.amis.hr (smtp.sm.srv.amis.hr [192.168.106.39]) by out.fsec.sm.srv.amis.hr with ESMTP id syk2b8bsx-1 for ; Sun, 05 Dec 2010 17:59:07 +0100 A-Original-Client-UID: 188.129.106.69 splivalo Received: from [192.168.10.1] (cpe-188-129-106-69.dynamic.amis.hr [188.129.106.69]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: splivalo) by smtp.amis.hr (Postfix) with ESMTPSA id 21B23273 for ; Sun, 5 Dec 2010 17:59:07 +0100 (CET) Message-ID: <4CFBC4DB.90101@megafon.hr> Date: Sun, 05 Dec 2010 17:59:07 +0100 From: Mario Splivalo User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.15) Gecko/20101027 Lightning/1.0b1 Thunderbird/3.0.10 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Get the max viewd product_id for user_id References: <4CF8CC26.70206@megafon.hr> <4CFBC46D.1080105@megafon.hr> In-Reply-To: <4CFBC46D.1080105@megafon.hr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.2.15, 1.0.148, 0.0.0000 definitions=2010-12-05_06:2010-12-04, 2010-12-05, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=1 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx engine=6.0.2-1010190000 definitions=main-1012050079 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201012/27 X-Sequence-Number: 34863 On 12/05/2010 05:57 PM, Mario Splivalo wrote: > The issue in both approaches is that if I have two product_ids that are > viewed same number of times and share the first place as most viewed > products by that user, I'll get only one of them (LIMIT 1 OR MAX() can > only return one row :). > And then, to jump again into my own mouth - your approach, Jayadevan, correctly gives me both product_id's if they're viewed the same number of times. Mario