Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
How to remove the order clause of a subquery issued by Sequelize

When using Sequelize, I want to specify the order clause only for the main query, but the order clause is also applied to subqueries. How can I apply the order clause to the main query only?

environment

■ Sequelize version

3.30.4

■ RDB

MySQL 5.7

DB design

  • Parents
    • id
  • Children
    • id
    • parent_id

Relationships defined in Sequelize

Parents.hasMany(models.Children, {
    foreignKey: 'parent_id'
});
Children.belongsTo(models.Parents, {
    foreignKey: 'parent_id'
});

ORM

Parents.findOne({
    order: "id asc",
    include: [Children]
})

SQL

SELECT
    `Parents`.*,
    `Children`.`id` AS `Children.id`,
    `Children`.`parent_id` AS `Children.parent_id`,
FROM
    (
        SELECT
            `Parents`.`id`,
        FROM
            `Parents` AS `Parents`
        ORDER BY
            id asc
        LIMIT
            1
    ) AS `Parents`
    LEFT OUTER JOIN `Children` AS `Children` ON `Parents`.`id` = `Children`.`parent_id`
ORDER BY
    id asc;

subquery

ORDER BY id asc

I would like to delete the order

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!