Reply to comment

The reCAPTCHA PHP library was not found. Please install it into sites/all/modules/recaptcha/recaptcha.

Correcting "The" Sorting Problem in MySQL

Names that contain "The ", like "The Eagles", don't sort in a useful way. You can use MySQL string functions to rememdy this. Below is a quick trick to sort a table by a column containing names, ignoring names that begin with "The ".

SELECT
  IF (
    LEFT(my_name_column, 4) = 'the ',
    CONCAT(RIGHT(my_name_column, LENGTH(my_name_column) - 4), ', The'),
    my_name_column
  )
  AS my_sortable_name_column
FROM my_table 
ORDER BY my_sortable_name_column ASC

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
7 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.