[nmglug] query masters??
Andres Paglayan
andres at paglayan.com
Fri Mar 4 15:19:19 PST 2011
On Fri, 2011-03-04 at 15:20 -0700, Bill York wrote:
> with the trailing ;
>
> ---
> Bill York
> 762-233-7568
>
>
>
> On Fri, Mar 4, 2011 at 2:53 PM, Bill York <iago at pobox.com> wrote:
>
> try this
>
>
>
> SELECT parent_id, question_id, Max(id) AS LastRecord FROM
> xxYourTablexx GROUP BY parent_id, question_id HAVING
> parent_id="1"
>
yep,
since the table has a bunch of fields, and many are indexed and the
grouping wanted all indexes to be there, etc, etc,
I ended up running a first query exactly like that on those elements
only, (id, parent_id, question_id)
then mapping to the ids and retrieving the full records,
not super efficient, but kept the code clean and gets me exactly what i
needed,
(I am using active record as abstraction layer)
>
>
>
> ---
> Bill York
> 762-233-7568
>
>
>
>
> On Fri, Mar 4, 2011 at 2:48 PM, Andres Paglayan
> <andres at paglayan.com> wrote:
>
>
> Hey,
>
> I need a query for the following,
>
> given a table with this vales
>
> | id | parent_id | question_id |
> | 1 | 1 | 1 |
> | 2 | 1 | 1 |
> | 3 | 1 | 2 |
> | 4 | 1 | 2 |
>
>
> Knowing only that I am searching for the parent_id = 1
> I need a query that searches for
> parent_id = 1 and then for each matching record, the
> older entry,
> meaning the result should only have the records with
> id 2 and 4,
>
> any hint?
>
>
>
>
>
>
>
>
> _______________________________________________
> nmglug mailing list
> nmglug at lists.nmglug.org
> http://lists.nmglug.org/listinfo.cgi/nmglug-nmglug.org
>
>
>
>
>
>
>
> _______________________________________________
> nmglug mailing list
> nmglug at lists.nmglug.org
> http://lists.nmglug.org/listinfo.cgi/nmglug-nmglug.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nmglug.org/pipermail/nmglug-nmglug.org/attachments/20110304/24eda822/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5510 bytes
Desc: not available
URL: <http://lists.nmglug.org/pipermail/nmglug-nmglug.org/attachments/20110304/24eda822/attachment-0001.bin>
More information about the nmglug
mailing list