SQL - how to select words with certain values at the end of word

前端 未结 5 785
故里飘歌
故里飘歌 2021-01-04 10:02

iam new to sql and i would like to know how can I find the letter or symbol at the end of value in column called Name? E.g if i would find something i will

相关标签:
5条回答
  • 2021-01-04 10:34

    You're currently matching on: ..where 'Name' like '%es%'.

    Which equates to anything, then 'es' then anything else.

    Removing the last % changes the where to anything then 'es'.

    in short.. you need ..where 'Name' like '%es'

    0 讨论(0)
  • 2021-01-04 10:39

    The query ..where 'Name' like '%es' will find columns where name ends with "ES". But if we need to find column where name ends with either "E" or "S", the query would be

    .. where 'Name' LIKE '%[ES]'

    0 讨论(0)
  • 2021-01-04 10:42
    1. if you want to find name start with something like 'test' use => select name from table where name like 'test%'.
    2. if you want to find name end with something like 'test' use => select name from table where name like '%test'.
    3. if you want to find name start with s and end with h use => select name from table where name like 's%'and name like '%h' or simply select name from table where name like 's%h'.
    0 讨论(0)
  • 2021-01-04 10:47

    You have to remove the last %, so it will only select words ending with es.

    select * from table where Name like '%es'
    
    0 讨论(0)
  • 2021-01-04 10:48

    You can also use REGEX

    select distinct city from station where city REGEXP '[aeiou]$';
    

    Resources: To Know more about REGEXP

    0 讨论(0)
提交回复
热议问题