Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9052111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:05:07+00:00 2026-06-16T13:05:07+00:00

I have this query in MySQL and I need to convert this to rails

  • 0

I have this query in MySQL and I need to convert this to rails active record:

select p.*,x.* from
(select * from users  ,roles_users
 where users.id=roles_users.user_id and roles_users.role_id not in(2,3)) as P
left join  
(select * 
  from cad_dispaths as T
 where `startdate_dispatch` = 
       ( select max(`startdate_dispatch`)
           from cad_dispaths
          where users_id = T.users_id ))  x 
on   x.users_id = p.user_id      
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:05:08+00:00Added an answer on June 16, 2026 at 1:05 pm

    I think the best solution in this case is to use find_by_sql. An important caveat is that it is designed to work with fetching one kind of thing at a time. I don’t know the semantics of your application, so I can’t say if that’s what this query is doing, but it seems like it might not be.

    For example, you could do:


    User.find_by_sql(your_sql)

    Which would return a collection of user objects that satisfy that query. Any extra data, as of the last time I tried something like this (rails 2.3.x) would be shoved into attributes in each object in the collection. Pretty ugly, but it can be prettier than the alternatives, sometimes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have this mysql query: SELECT member_id, text FROM review WHERE text !=
I have written this query for retrieving data from mysql as below select FeedbackCode,EMailID,FeedbackDetail,
I have this query in MySQL: SELECT pr.*, pr7.value AS `room_price_high` FROM `jos_hp_properties` pr
I need to have MySQL query like this one: UPDATE table_name SET 1 =
Background: I have this with rollup query defined in MySQL: SELECT case TRIM(company) when
I have a select query in mysql . On each execution of this query
I have this mysql query (evolving two tables : Users and Files ) that's
I have a MySQL standard query that I need to convert into a Zend_Db_Select
I have a SQL Server query that I need to convert to MySQL. I've
I have the following query that I need to convert to rails like syntax.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.