How can I get results within a range in MySQL, where some fields have letters?

50 views Asked by At

I have the following data in a sku column:

UX1905
UX1906
UX1907
UX1907a
UX1907b
UX1908
UX1908X
UX1909
UX1910
UX1911
OP778
OP779
OP800

I want to create a MySQL query that gets all skus from the range of UX1906-UX1909, including the skus with the characters at the end of them.

Any ideas on how I would do something like this?

Can I use BETWEEN with LIKE somehow for this?

2

There are 2 answers

0
Nuri Tasdemir On BEST ANSWER

This works in postgresql and possibly in mysql too.

SELECT * FROM table_name WHERE sku BETWEEN 'UX1906' AND 'UX1909'
0
Clyde Winux On

Try:SELECT * FROM my_tbl WHERE sku_val between 'UX1906' and 'UX1909'