I want to write a query that will match up a string from one table with the closest alphabetical match of a string fragment within another table.
Given: There are 2 tables, table 1 has a record with string "gumby". Table 2 has letters that start words: "g", "ga", "gam", "go", "ha", "hi".
Problem: Because I don't have a "gu" entry or anything more specific (like "gum"), I want "gumby" to match up with "go", because alphabetically "gumby" is less than "h" and more than "go".
Mechanisms I have tried:
1. A statement with "LIKE g%" will return all fragments starting with "g", I only want one result.
2. A statement with "LIKE "g%" and a GROUP BY. That only returns "g".
3. Adding MAX() to that GROUP BY statement will give me "go", but that's not correct if my word were "galaga" -- the correct spot for that would be "ga".
I would really like to accomplish this alphabetizing words solely in SQL.