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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:26:20+00:00 2026-05-19T04:26:20+00:00

Why does doctrine (1.2) use WHERE IN instead of LIMIT ? This code: Doctrine_Query::create()

  • 0

Why does doctrine (1.2) use WHERE IN instead of LIMIT?

This code:

Doctrine_Query::create()
   ->from('Table t')
   ->limit(10)
   ->getSqlQuery();

Returns something like this:

SELECT t.id_table AS t__id_table FROM table AS t WHERE t__id_table IN (1,2,3,4,10,12,18,20,21,25);

Instead of this:

SELECT t.id_table AS t__id_table FROM table AS t LIMIT 10;

This behaivor is same for any LIMIT value. This generates a very long queries for high LIMIT values.

Bonus question: How does Doctrine know, what ids to use? (By sending another query to DB??)

  • 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-05-19T04:26:21+00:00Added an answer on May 19, 2026 at 4:26 am

    That’s because LIMIT operates on database rows not “objects”. When you type $q->limit(10) you want to get ten objects, not ten rows from database.

    Consider following query (products and categories have many-to-many relationship):

    SELECT p.*, c.* FROM product p 
    INNER JOIN product_category_ref pcr ON p.id = pcr.prodcut_id
    INNER JOIN category c ON c.id = pcr.category_id
    WHERE p.price < 123;
    

    To fetch 10 products (objects) your query will have to fetch at least 20 rows. You cannot use LIMIT 10 cause (just for example) only 3 products would be returned. That’s why you need to find out which products should be fetched (limit applies to products), and later fetch the actual data.

    That will result in following queries:

    SELECT p.id FROM product p WHERE p.price < 123;
    SELECT ..... WHERE p.id IN (...);
    

    Second query might return 20, 423 or 31 rows. As you can see that’s not a value from limit().

    PS. Doctrine2 is much more clearer in that case as it’s using setMaxResults() method instead of limit() which is less confusing.

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

Sidebar

Related Questions

Does using prepared statements in Zend_DB or Doctrine protect me from sql injection? example:
does anyone know a way to write a Doctrine migration to change the Table
I've a question related to Doctrine 2 and Zend Framework. If you use Zend
Does anyone know of an existing implementation of a sortable behavior for Doctrine? I'm
I'm integrating doctrine with Zend Framework. I've hit an error thrown from cli. It
I'm using YAML to define the doctrine schema and would like to start the
I'm using symfony 1.4 and doctrine. I've spent the last couple days playing with
InvalidArgumentException widget attention does not exist When I remove attention, captcha gives the same
For a website i'm building I need to check wether a location has contracts,
I need to determine if user has already visited a page, for tracking unique

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.