# Searching multiple tables

**URL:** <https://www.ruby-forum.com/t/searching-multiple-tables/152933>\
**Category:** Rails\
**Created:** [November 10, 2008, 3:30am UTC](https://www.ruby-forum.com/t/searching-multiple-tables/152933 "2008-11-10T03:30:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [November 10, 2008, 3:30am UTC](https://www.ruby-forum.com/t/searching-multiple-tables/152933/1 "2008-11-10T03:30:19Z")

</div>

Hey,  
I have three tables/models - stories, pictures, videos. I want to  
be able to search all of these at once to find entries within a date  
range. Currently I am searching each one and pushing the results onto  
an array which I paginate and display. This doesn’t work correctly  
because it doesn’t sort correctly and seems like a poor solution.

Additionally it would be helpful to be able to sort a date range and  
if that fails to find the 10 most recently added entries. This seems  
like a simple find but I’m not sure exactly how to do it.

Thanks for any help.  
JB

---

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [November 18, 2008, 8:55pm UTC](https://www.ruby-forum.com/t/searching-multiple-tables/152933/2 "2008-11-18T20:55:02Z")

</div>

Hi Jables,

There are no magic solution for what you’re trying to do.

What you can do is search each model and use a 4th model as the search  
result… using that search result model to paginate and display your  
page.

This way you should be able to sort in different fashion as made the  
query much more efficient.

One question I have for you is how do you trigger the search?

Regards,

Jean-Marc

> **[M2i3 - Connecter les besoins aux solutions](https://m2i3.com/)**
>
> Nous sommes M2i3, des "socials-geeks" passionnés par le web, l'infonuagique et les logiciels. Nous vous présentons IncognitoDesk Après des an ...
