2

How can i concatenate 2 LIKE operator as 1 for below query ?

select * from students where name LIKE 'abc%' OR name like '% abc%'

Please notice " " space after % wildcard in second like operator before 'abc'.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
Shabbir Panjesha
  • 438
  • 1
  • 4
  • 12
  • 2
    SQLite3 does support `REGEXP` though it requires a user defined function, which is not possible on Android. Hence, your current query is probably the best you can do. – Tim Biegeleisen Feb 17 '17 at 15:30

2 Answers2

4

Just ensure that all strings have that space:

SELECT * FROM students WHERE ' ' || name LIKE '% abc%';
CL.
  • 173,858
  • 17
  • 217
  • 259
1

For most databases, the LIKE operator has pretty limited pattern matching (especially if you're used to regex-type pattern matching). SQLite is, as far as I can tell, one that fits that description. No one LIKE pattern can do what you describe.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • SQLite3 supports `REGEXP` which _can_ handle the OP's logic in one expression, though sadly this isn't possible on Android which does not support user defined functions. – Tim Biegeleisen Feb 17 '17 at 15:31