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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:49:44+00:00 2026-05-21T14:49:44+00:00

RIGHT JOIN (SELECT * FROM images ORDER BY image_id) AS `i` ON i.ad_id =

  • 0
RIGHT JOIN (SELECT * FROM images ORDER BY image_id) AS `i` ON i.ad_id = a.id

How to order joined table without using temporary table? 🙂

Because it’s 5x slower than simple join:

RIGHT JOIN images AS `i` ON i.ad_id = a.id

And there are problems with fields list, which should be duplicated inside subquery as well to avoid using * sign.

Thanks 😉

Update

SELECT a.id, GROUP_CONCAT(image_id) AS `image_ids`
FROM `ads` AS `a`
RIGHT JOIN (SELECT * FROM images ORDER BY image_id) AS `i` ON i.ad_id = a.id
GROUP BY `a`.`id`
ORDER BY `a`.`id` DESC

There are multiple rows that match per id in joined table. That’s why i need to order them.

group_concat(image_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-05-21T14:49:45+00:00Added an answer on May 21, 2026 at 2:49 pm

    Order by image_id after the join.

    (You do have an index on image_id, don’t you?)

    UPDATE:

    You can put the ORDER BY inside your GROUP_CONCAT:

    GROUP_CONCAT(image_id ORDER BY image_id)
    

    and then you don’t need the subquery.

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

Sidebar

Related Questions

Hi i've wrote a query that works: SELECT `comments`.* FROM `comments` RIGHT JOIN (SELECT
I have the following query SELECT * FROM attend RIGHT OUTER JOIN noattend ON
I'm a little confused regarding the left and right join operators. select * from
Using the following query select * from table1 left join table2 on table1.name =
SELECT `a`.`department`, `a`.`category`, `a`.id, (SELECT group_concat(t_0) FROM images WHERE ad_id=a.id) t_0, (SELECT group_concat(t_1) FROM
Two snippets of MySQL: SELECT * FROM annoyingly_long_left_hand_table LEFT JOIN annoyingly_long_right_hand_table ON annoyingly_long_left_hand_table.id =
I have a right outer join, that almost does what I want... SELECT users_usr.firstname_usr,
The RIGHT JOIN on this query causes a TABLE ACCESS FULL on lims.operator .
I have the following query: select * from ACADEMIC a left join RESIDENCY r
I have this query: select top(2) property_id_ref ,image_file ,property_name from property_master a inner join

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.