Skip to content
Advertisement

How to select data using like with out consider after character in laravel or sql

I have a table call labels_table.


id label
1 A_1_1
2 A_1_2
3 A_2_1
4 A_4_1
5 A_10_1
6 A_11_1

I need to select all the labels for A_1 group. A_1_1 and A_1_2 should be the correct labels.

I used the following query.

sql

Larval

But both SQL and laravel queries returns all A_1_1, A_1_2, A_10_1 and A_11_1. But I need to get only A_1_1 and A_1_2.

Please explain what’s the issue here and give me a solution. thank you.

Advertisement

Answer

LIKE allows you to escape the wildcard characters. The default is backslash:

However, you can also set your own:

Or use regular expressions:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement