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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:57:32+00:00 2026-05-23T15:57:32+00:00

Lets say I have the following query. SELECT stringdata FROM table ORDER BY FIELDS(

  • 0

Lets say I have the following query.

SELECT stringdata FROM table ORDER BY FIELDS( stringdata, 'tg','nk','mg','pl') asc;

For some reason I’m getting the results at the very bottom. How can I get the query to put the results starting from ‘tg’ at row 1 rather than the last row in the results?

Not only that but there’s more than one ‘tg’ in the data, I’d like it to sort it in this expected output:

stringdata
__________
   'tg'
   'tg'
   'tg'
   'nk'
   'nk'
   'mg'
   'mg'
   'mg'
   'pl'

So far using ORDER BY Fields() is only sorting one instance of the data rather than all.

Using desc instead of asc in the query works as expected. I get 'pl' on the first row, then 'mg', 'nk', etc.

  • 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-23T15:57:32+00:00Added an answer on May 23, 2026 at 3:57 pm

    Normally the FIELD clause in ORDER BY works something like

    SELECT * FROM table ORDER BY FIELD(field, high_priority, second_high,
                   ,....., low_priority);
    

    So in your query, the sorting took place as you mentioned and when you gave the ASC it printed from the lowest_priority. So, for your case, if you want tg at the top, you can either reorder the priority in the FIELDS or as you have already tried use desc

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

Sidebar

Related Questions

Let's say I have the following query: SELECT anInteger FROM table; How do I
Let's say I have the following simple query SELECT TOP 1 name FROM months
Let's say I have the following query. SELECT ID, Email, ProductName, ProductModel FROM Products
Let's say I have the following SQL query: SELECT * FROM employee INNER JOIN
Lets say I have the following mapping: <hibernate-mapping package=mypackage> <class name=User table=user> <id name=id
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
Let's say I have the following SQL query: SELECT Meeting.id AS meetingId, Bill.id AS
I have the following SQL query: select ID, COLUMN1, COLUMN2 from (select ID, COLUMN1,
Let's say I have a table with the following contents: (just some random values)
I have the following query: SELECT DISTINCT sites.site_id, sites.site_name, sites.site_url, earnings.cust_id FROM sites, earnings

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.