# Mysql query

**URL:** <https://www.ruby-forum.com/t/mysql-query/143414>\
**Category:** Rails\
**Created:** [July 18, 2008, 7:52am UTC](https://www.ruby-forum.com/t/mysql-query/143414 "2008-07-18T07:52:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrbless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ba9def/32.png) [@mrbless](https://www.ruby-forum.com/u/mrbless)\
**Post date:** [July 18, 2008, 7:52am UTC](https://www.ruby-forum.com/t/mysql-query/143414/1 "2008-07-18T07:52:38Z")

</div>

Hi Everybody I have a table called mail which is as follows:

id user\_id message\_id conversation\_id created\_at  
== ===== ========= =========== =================  
22 2 12 10 2008-07-17  
18:18:38  
23 3 12 10 2008-07-17 18:18:39  
24 1 12 10 2008-07-17 18:18:39  
25 2 13 10 2008-07-17 18:29:16  
26 1 13 10 2008-07-17 18:29:16  
27 3 13 10 2008-07-17 18:29:17  
28 1 14 11 2008-07-17 19:23:09  
29 3 14 11 2008-07-17 19:23:10  
30 2 14 11 2008-07-17 19:23:09

# Now i want only those unique tuples whose conversation\_id are same but out of it I want the latest i.e order by created\_at desc. but I want all attributes. This is what I want for as an output

id user\_id message\_id conversation\_id created\_at  
== ===== ========= =========== =================  
27 3 13 10 2008-07-17 18:29:17  
29 3 14 11 2008-07-17 19:23:10

---

<div class="post-metadata">

**Author:** ![mrbless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ba9def/32.png) [@mrbless](https://www.ruby-forum.com/u/mrbless)\
**Post date:** [July 18, 2008, 8:10am UTC](https://www.ruby-forum.com/t/mysql-query/143414/2 "2008-07-18T08:10:47Z")

</div>

U can do like.

conversation\_ids \<\< [10,11]  
for conversation in conversation\_id  
@my\_mail \<\< Mail.find(:last,:conditions =\>  
[‘conversation\_id=?’,conversation])  
end

i hope it will work 🙂

---

<div class="post-metadata">

**Author:** ![mrbless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ba9def/32.png) [@mrbless](https://www.ruby-forum.com/u/mrbless)\
**Post date:** [July 18, 2008, 11:18am UTC](https://www.ruby-forum.com/t/mysql-query/143414/3 "2008-07-18T11:18:47Z")

</div>

thank for your reply. I resolved it in the similar fashion.

On Jul 18, 11:09 am, “bala kishore pulicherla” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
