# Sequel: Get latest record of multiple

**URL:** <https://www.ruby-forum.com/t/sequel-get-latest-record-of-multiple/105874>\
**Category:** Ruby\
**Created:** [June 4, 2007, 7:15am UTC](https://www.ruby-forum.com/t/sequel-get-latest-record-of-multiple/105874 "2007-06-04T07:15:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florian\_ASSSSmann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/48db29/32.png) [@Florian\_ASSSSmann](https://www.ruby-forum.com/u/Florian_ASSSSmann)\
**Post date:** [June 4, 2007, 7:15am UTC](https://www.ruby-forum.com/t/sequel-get-latest-record-of-multiple/105874/1 "2007-06-04T07:15:39Z")

</div>

Hi there,

first of all I’d like to say that Sequel seems very promising, thank  
you Sharon. I’m currently writing a threaded daemon and I can’t  
figure out how to build this SQL String.

I have an array of category ids which I use to select import records:  
db[:imports].filter :category\_id =\> categories.map(:id)

Since a category has multiple imports I only want the latest Import  
before a Date X for each category. Is this even possible?

Sincerely  
Florian

---

<div class="post-metadata">

**Author:** ![Florian\_ASSSSmann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/48db29/32.png) [@Florian\_ASSSSmann](https://www.ruby-forum.com/u/Florian_ASSSSmann)\
**Post date:** [June 4, 2007, 8:26am UTC](https://www.ruby-forum.com/t/sequel-get-latest-record-of-multiple/105874/2 "2007-06-04T08:26:18Z")

</div>

Florian AÃŸmann wrote:

> Hi there,
> 
> first of all I’d like to say that Sequel seems very promising, thank  
> you Sharon. I’m currently writing a threaded daemon and I can’t  
> figure out how to build this SQL String.
> 
> I have an array of category ids which I use to select import records:  
> db[:imports].filter :category\_id =\> categories.map(:id)
> 
> Since a category has multiple imports I only want the latest Import  
> before a Date X for each category. Is this even possible?
> 
> Sincerely  
> Florian

Hi Florian,

I think that you need a field in that table in which you have to put the  
timestamp. Maybe this feature that you want is present in some advanced  
RDBMS like Oracle/DB2 or maybe Postgresql.

Best regards,

Alin

---

<div class="post-metadata">

**Author:** ![Florian\_ASSSSmann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/48db29/32.png) [@Florian\_ASSSSmann](https://www.ruby-forum.com/u/Florian_ASSSSmann)\
**Post date:** [June 5, 2007, 12:06am UTC](https://www.ruby-forum.com/t/sequel-get-latest-record-of-multiple/105874/3 "2007-06-05T00:06:49Z")

</div>

Hi Alin,

Am 04.06.2007 um 08:26 schrieb Alin P.:

> Hi Florian,
> 
> I think that you need a field in that table in which you have to  
> put the  
> timestamp. Maybe this feature that you want is present in some  
> advanced  
> RDBMS like Oracle/DB2 or maybe Postgresql.

I defined some methods in my Model that - hopefully - build me up the  
query, still needs to be tested though. As the moment I’m having  
sequence problems when I try to create Records… ☹

Sincerely  
Florian

P.S. I’m using PostgreSQL 8.1
