mysql - Match on substring -


how following query? want match on entire string minus last 2 characters. in python be:

>>> x='hello' >>> x[:-2] 'hel' 

conceptually, in sql be:

select * main_tmp vid_country_key[:-2] = '2wh_gqwkmqg' 

how this? , above faster or slower than:

select * main_tmp vid_country_key '2wh_gqwkmqg%' 

as know, 2 example queries provided not equivalent, altering second should give same results first, , might keep potential indexing advantage of second:

select *  main_tmp  vid_country_key '2wh_gqwkmqg%'    , length(vid_country_key) = length('2wh_gqwkmqg')+2 ; 

if doesn't use index (assuming there one), try changing and having, or use index.

oh, record, if wanted know actual syntax first example,

where left(vid_country_key, greatest(length(vid_country_key)-2, 0)) = '2wh_gqwkmqg' 

the greatest need in case length of field less 2.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -