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

  • Home
  • SEARCH
  • 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 287789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:45:26+00:00 2026-05-12T05:45:26+00:00

Here are my DB tables: Field – ID, name Order – Order ID, name,

  • 0

Here are my DB tables:

Field
  - ID, name
Order
  - Order ID, name, etc.
OrderField
  - Order ID
  - Field ID
  - Value

For example, a Field name may be “First Name,” and the OrderField value may be “James.”

Using a MySQL query only, how can I efficiently sort Orders based on the OrderFields? To be a little more specific:

Say I want a list of orders sorted by the “First Name” field, and I already have its field ID. How can I write the query to include an ORDER BY statement to sort by the “First Name” OrderField associated with the order?

  • 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-12T05:45:27+00:00Added an answer on May 12, 2026 at 5:45 am

    Your query should be something like:

    SELECT Order.*, OrderField.Value
      FROM Order
      LEFT OUTER JOIN OrderField ON Order.`Order ID` = OrderField.`Order ID`
     WHERE OrderField.`Field ID` = :firstNameFieldId
     ORDER BY OrderField.Value
    

    :firstNameFieldId is the id of the “First Name” field.
    Outer join is used in case you have orders that do not have “First Name” field populated – they’ll still be retrieved in this case. If you’re sure this will never happen (or you don’t want them selected) replace it with an inner join.

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

Sidebar

Related Questions

I have a bit of an SQL problem. Here are my tables: areas(id, name,
I have two tables, each with an id field. Here are the two tables:
We have a table, name 'employeeReg' with fields employeeNo | employeeName | Registered_on Here
Well here's my problem I have three tables; regions, countries, states. Countries can be
Here is a simplified version of my database model. I have two tables: Image,
I have a project here that connects to an in-production database and grabs tables
Let's say you have two tables, Users and UserRoles. Here's how the two tables
I have two tables here both contain like lots of records in the tens
Let's say we have two tables here , posts and comments, the relations is
I have several tables where a field is for priority (1 to 5). Problem

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.