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 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 need to make a synonym search function, using MySQL. Here is the tables
Here's some background info. I have three MySQL tables (all InnoDB). The first table
I have two tables with a single common field. Here is how these two
Here is a table structure (e.g. test): Field Name Data Type id BIGINT (20)
Here are my tables in mysql: ----------------1------------------------- +---------------------------+----------+ | email | attempts | +---------------------------+----------+
I have Views field from one of my tables in the database. At first
Here's a fun one. Occasionally we may want to find the tables consisting of
So imagine 2 big mysql tables imported from Excel. Table1 has the field SNameID,
I have two tables, each with an id field. Here are the two tables:
I have a bit of an SQL problem. Here are my tables: areas(id, name,

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.