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 7995053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:17:49+00:00 2026-06-04T14:17:49+00:00

I am receiving a set of models from my SQLite Database with Ruby on

  • 0

I am receiving a set of models from my SQLite Database with Ruby on Rails 2.3.5. Currently I am using a subquery in order to select only the ones which I really want to have:

find(:all, 
  :conditions => "foo.id in (
                    SELECT bar.foo_id FROM bar
                    JOIN baz
                      ON baz.bar_id = bar.id
                    WHERE baz.bla in (1, 2, 3)
                  )"
)

I know this is stupid, because the subquery evaluates the same result for every row and I guess SQLite is not smart enough to notice that it could be optimized. So I would like to take it out of the query. I know that I could simply call it from Rails using a second find(), but given that the return value of the subquery may become relatively big, I would like to do everything in the database, so I don’t need to juggle huge data between the Database and Rails.

So, how can I do the Model’s find() and tell it, that it should look up the return value of my actual subquery and then use it’s result for the comparison of my other rows? Can I pass this in one call of find() into SQLite?

  • 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-04T14:17:51+00:00Added an answer on June 4, 2026 at 2:17 pm

    I wonder if you could do something like the following:

        subs = connection.select_rows("SELECT bar.foo_id FROM bar
                                       JOIN baz
                                       ON baz.bar_id = bar.id
                                       WHERE baz.bla in (1, 2, 3)")
        find(:all, :conditions => "foo.id in (#{subs.join(',')})")
    

    Which is what I’d try to rewrite it to in Rails 3.

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

Sidebar

Related Questions

I am currently not receiving the last object from my object stream until another
I'm using: Paperclip 2.3.16 Rails 3.0.9 Ruby 1.9.2 AWS - S3 0.6.2 I'm trying
I am receiving Object reference not set to an instance of an object. when
I'm receiving errors from Gtk that I can't track down. Every time my mouse
I'm receiving deserialized object using WCF (trying to get latitude and longitude using google
I am receiving an error from the SharpArchitecture model binder. Collection was modified; enumeration
My app is now receiving push notifications from two different PHP scripts on our
I'm receiving the error local variable box is accessed from within inner class; needs
I'm designing a tool using Java 6, that will read data from Medical Devices.
i am trying to set up form validation but keep receiving Parse error: 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.