Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL – How to retrieve columns that end with one of characters in a list

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you.

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading