<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.28.3">
</HEAD>
<BODY>
On Fri, 2011-03-04 at 15:20 -0700, Bill York wrote:<BR>
<BLOCKQUOTE TYPE=CITE>
with the trailing ;<BR>
<BR>
---<BR>
Bill York<BR>
762-233-7568<BR>
<BR>
<BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
On Fri, Mar 4, 2011 at 2:53 PM, Bill York <<A HREF="mailto:iago@pobox.com">iago@pobox.com</A>> wrote:<BR>
<BLOCKQUOTE>
try this
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
SELECT parent_id, question_id, Max(id) AS LastRecord FROM xxYourTablexx GROUP BY parent_id, question_id HAVING parent_id="1"
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
yep,<BR>
<BR>
since the table has a bunch of fields, and many are indexed and the grouping wanted all indexes to be there, etc, etc,<BR>
I ended up running a first query exactly like that on those elements only, (id, parent_id, question_id)<BR>
<BR>
then mapping to the ids and retrieving the full records,<BR>
not super efficient, but kept the code clean and gets me exactly what i needed,<BR>
(I am using active record as abstraction layer)<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
<BR>
---<BR>
Bill York<BR>
762-233-7568<BR>
<BR>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
On Fri, Mar 4, 2011 at 2:48 PM, Andres Paglayan <<A HREF="mailto:andres@paglayan.com">andres@paglayan.com</A>> wrote:<BR>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
<BLOCKQUOTE>
Hey,<BR>
<BR>
I need a query for the following,<BR>
<BR>
given a table with this vales<BR>
<BR>
| id | parent_id | question_id |<BR>
| 1 | 1 | 1 |<BR>
| 2 | 1 | 1 |<BR>
| 3 | 1 | 2 |<BR>
| 4 | 1 | 2 |<BR>
<BR>
<BR>
Knowing only that I am searching for the parent_id = 1<BR>
I need a query that searches for<BR>
parent_id = 1 and then for each matching record, the older entry,<BR>
meaning the result should only have the records with id 2 and 4,<BR>
<BR>
any hint?<BR>
<BR>
<BR>
<BR>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<BR>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
<BLOCKQUOTE>
_______________________________________________<BR>
nmglug mailing list<BR>
<A HREF="mailto:nmglug@lists.nmglug.org">nmglug@lists.nmglug.org</A><BR>
<A HREF="http://lists.nmglug.org/listinfo.cgi/nmglug-nmglug.org">http://lists.nmglug.org/listinfo.cgi/nmglug-nmglug.org</A><BR>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
<BR>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BR>
<PRE>
_______________________________________________
nmglug mailing list
<A HREF="mailto:nmglug@lists.nmglug.org">nmglug@lists.nmglug.org</A>
<A HREF="http://lists.nmglug.org/listinfo.cgi/nmglug-nmglug.org">http://lists.nmglug.org/listinfo.cgi/nmglug-nmglug.org</A>
</PRE>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>