Question

is that possible to use MySQL BETWEEN clause between two LIKE clause?

say I want to search whose name start with A,

SELECT * FROM my_table WHERE name_column LIKE "A%"

if I want to search whose name start with J,

SELECT * FROM my_table WHERE name_column LIKE "F%"

Now if I want to search whose name start with A-J, is that possible,

SELECT * FROM my_table WHERE name_column BETWEEN LIKE "A%" AND LIKE "%F"

Please help me find some easy solution for that.

Was it helpful?

Solution

You don't need the '%' when matching a range, as it is implied in the ordering

SELECT * FROM my_table WHERE name_column >= 'A' AND name_column < 'K';

OTHER TIPS

In this case, a Regular Expression may be handy

SELECT * FROM my_table WHERE name_column RLIKE "^[A-J].*$";

Mysql command here

$qry = select * from my_table where name_column between '%$A%' and '%$J%';

Let it not be

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top