I'm trying to learn sql and figuring out a way to retrieve all columns whose name ends with one of characters in an a list (using JDBC queries):
public Map<Long, Set<Long>> groupCountriesBy(Set<Integer> countryIdLastDigits) {
String query = "SELECT c.id FROM countries c"
" WHERE c.name LIKE '%[dea]'"
" GROUP BY c.name ";
var args = new MapSqlParameterSource("countryIdLastDigits", countryIdLastDigits);
....
}
WHERE c.name LIKE '%[dea]'
does return all columns that end with either d, e or a but did not manage to find a way to pass countryIdLastDigits to this sql query.
Could you please share with me some pointers / hints ? Probably I'm missing few SQL concepts / commands.
Thank you.
CodePudding user response:
Most SQL dialects have left and right string functions so perhaps something like
where right(col,1) in ('d', 'e', 'a')
will be all you need.