• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Query-string to Active Records

#1
[eluser]Patrick Reck[/eluser]
I have this SQL Query which works fine in it self. However, I can't quite figure how to write it in Active Record. How can I do this?

Code:
SELECT
  users.*,
  users_info.*,
  mail.*
FROM
  `users`
  JOIN `mail` ON `users`.`id` = `mail`.`user_from`
  JOIN `users_info` ON `users_info`.`user_id` = `mail`.`user_from`
  JOIN (
    SELECT  user_from, MAX(date) AS date
    FROM mail
    WHERE user_to = '1'
    GROUP BY user_from
  ) most_recent ON mail.user_from = most_recent.user_from AND mail.date = most_recent.date
  WHERE `user_to` =  '1'

#2
[eluser]Otemu[/eluser]
Hi,

You can't do sub queries in active record, there a some libraries that allow you to achieve this if you google for them. Your not forced to use active record so just use normal mysql to achieve your goal.

#3
[eluser]Patrick Reck[/eluser]
[quote author="Otemu" date="1358952905"]Hi,

You can't do sub queries in active record, there a some libraries that allow you to achieve this if you google for them. Your not forced to use active record so just use normal mysql to achieve your goal.[/quote]

I was just hoping for a Active Record solution. I guess I'll just have to do it the old way, thank you


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.