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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:42:06+00:00 2026-06-17T16:42:06+00:00

Please I have the following tables Field +—-+——–+———-+———————+ | id | name | Type

  • 0

Please I have the following tables

Field
+----+--------+----------+---------------------+
| id | name   | Type     | date                |
+----+--------+----------+---------------------+
|  1 |  price | int      | 2009-09-02 00:07:07 |
|  2 |  width | float    | 2009-09-02 00:07:08 |
|  3 |  height| float    | 2009-09-02 00:07:30 |
+----+--------+--------------------------------+


Post
+----+--------+---------------------------------+
| id |title   | Body                            |
+----+--------+---------------------------------+
|  1 |  test  | Bla bla bla                     |
|  2 | Hello  | Bla bla bla                     |
|  3 | Its me | Bla bla bla                     | 
+----+--------+---------------------------------+


Post_Annex
+----+--------+----------+---------------------+
| id | IdPost | IdField  | Value               |
+----+--------+----------+---------------------+
|  1 |  1     | 1        | 50                  |
|  2 |  1     | 2        | 21                  |
|  3 |  1     | 3        | 3                   |
|  4 |  2     | 1        | 10                  |
|  5 |  2     | 2        | 2                   |
|  6 |  2     | 3        | 150                 |
|  7 |  3     | 1        | 1                   |
|  8 |  3     | 2        | 25                  |
|  9 |  3     | 3        | 15                  |
+----+--------+--------------------------------+

And I desire to select data from the Post and Post_Annex tables, group them by the Id of the Post table and order them by the price (this mean by IdField of the Post_Annex table when its equal to 1). So this is my query :

SELECT p.title
    FROM Post p
    LEFT JOIN Post_Annex pa
       ON p.id = pa.IdPost

    GROUP BY p.id

    ORDER BY case when pa.IdField = 1 then 0 else 1, pa.Value DESC

This gave me the result in this order : its Me | Hello | test

This is fine. But even if I try the order by the width (IdField = 2) or height (IdField = 3) it gave me the same result.

Please masters any Idea to help me resolving this ? Thanks in advance.

  • 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-17T16:42:06+00:00Added an answer on June 17, 2026 at 4:42 pm

    I would just modify the join clause, to specify which field you want to sort:

    SELECT p.title
    FROM Post p
         LEFT JOIN Post_Annex pa
         ON p.id = pa.IdPost
            AND pa.idfield=1
    ORDER BY pa.Value DESC
    

    and then you don’t have to group by p.id.

    Your query doesn’t always work because you are grouping by p.id but you are selecting (and ordering by) other nonaggregated columns, and the values of those columns can be undetemined.

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

Sidebar

Related Questions

I have the following 2 tables.. mysql> describe catalog_category_reference; +----------+---------+------+-----+---------+----------------+ | Field | Type
I have the following table structure: +----------+------------------------+------+-----+------------------------------------------+----------------+ | Field | Type | Null |
please have a look at the following code import java.util.ArrayList; import java.util.List; public class
Please have a look at the following code namespace Funny { class QuesionsAndAnswers {
Please have a look at the following code: $(#saveButton).click(function(){ $this = $(#tableData).find(input:checked).parent().parent(); tea =
Please have a look at the following machine code ‎0111001101110100011100100110010101110011011100110110010101100100 This means something. I
Please have a look at the following code package Euler; import java.util.ArrayList; import java.util.List;
I have following UML class diagram and java coding for each, please tell me
I have HttpClient 4.1. Please have a look at following program: import org.apache.http.client.methods.*; import
In my current project, Workflows have comments. Please have a look at the following

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.