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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:42:04+00:00 2026-05-25T19:42:04+00:00

Basically I have a PHP MYSQL query which returns 16 items. 15 of them

  • 0

Basically I have a PHP MYSQL query which returns 16 items. 15 of them start with letters A-Z, and one starts with a number (the name of a product is “3d Star Gazer”). In a regular query, sorting alphabetically displays this one item that starts numerically first. I want the list to be sorted alphabetically, with the 3d Star Gazer displayed last.

Is this possible?

SELECT t1.id, t2.name, t2.manufacturer
FROM db.t1
  LEFT JOIN db.t2 ON t1.id = t2.id
WHERE year = '2011'
ORDER BY t2.name ASC

I saw this link: Sort MySQL results alphabetically, but with numbers last but the solution wasn’t working for me…

As a secondary question, is it possible to not include the word “The” in the sort? For example, a game is called “The Guessing Game,” I want it to appear sorted as “G”, not as “T”.

  • 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-25T19:42:05+00:00Added an answer on May 25, 2026 at 7:42 pm

    Using the IF() operator and adding two columns to control the sort order:

    SELECT t1.id, t2.name, t2.manufacturer,
       IF(LEFT(t2.name, 1) BETWEEN '0' AND '9', 2, 1) as sortOrder1,
       IF(t2.name LIKE 'The _%', SUBSTRING(t2.name FROM  5), t2.name) as trimmedName
    FROM db.t1
       LEFT JOIN db.t2 ON t1.id = t2.id
    WHERE year = '2011'
    ORDER BY sortOrder1, trimmedName;
    

    The underscore in the pattern for the LIKE operator matches any single character, and is used to make sure that the returned substring will not be null.

    If you don’t want the extra columns in your final output, wrap the above select statement inside another:

    SELECT id, name, manufacturer FROM ([select statement above]) a;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query which returns 3 fields, one of which is the month
I have a MySQL query in which I want to include a list of
I have the following PHP/MySQL code: function executeMultirowQuery($query) { $result = mysql_query($query); $table =
I want to build a mySQL query, which returns all nodes in a graph
I have a table in my MySQL DB which basically contains cron-like tasks. Basically
Basically I have a single page on my site that I want any php
I have a very large php maintenance script (basically it recreates thumbnails for an
Basically, we have an ASP website right now that I'm converting to PHP. We're
I basically have a page which shows a processing screen which has been flushed
I have a mySQL table which contains rows based on payments. Each row contains

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.