Assuming you don't want to change the contents of the table (and therefore get slightly less efficient queries), the following should do the trick.
(If you have the leisure time to change the table, see Suggestions at the end of this answer)
SELECT Title FROM myTable WHERE (Title LIKE 'x%' OR Title LIKE 'THE x%')
Notes:
- x indicate the desired letter (example: LIKE "A%", etc.)
- The additional condition "AND THE TITLE DOES NOT LIKE" is necessary only when "X" is the letter "T" (otherwise it is functionally redundant, but does not change the result)
- I'm not sure about the support [^xyz] (that is, NOT characters x, y or z), so [^T] can be replaced with its positive equivalent say [A-RS-Z0-9] .
There are several other stop words to consider ("A", "AN", "OF" ...), but for books or movie titles, it is common practice to consider only "THE". If you must deal with other articles, the logic can be expanded, as in:
SELECT Title FROM myTable WHERE (Title LIKE 'x%' OR Title LIKE 'THE x%' OR Title LIKE 'A x%' OR Title LIKE 'AN x%')
There are better solutions if you can change the contents of the table . Some of them involve the preliminary calculation of one or more additional columns (and their preservation / adding them when adding new records, etc.).
- See for example Cletus’s answer in this post for the sort_column approach, where the extra column contains a header that is free of any unwanted leading noise word. In addition to its purpose, as a filtering field in the problem of finding the initial letters OP, this column can also be used to more conveniently and intelligently sort heading lists created by a filter that is not associated with the initial letter and / or the beginning of the name (say, search by year).
- The option above is to store only the “effective” initial letter (minus unwanted noise), making the column smaller, but less universal.
- The heading column itself can be updated to preserve the changed heading shape, as a result of which extraneous leading noise words move to the end of the line between the brackets. This practice is quite common in bibliographic-type catalogs.
source share