1

I wrote query for filter data using name and wrote following query

SELECT * FROM (`abc`) WHERE (name LIKE "%test\'!&@#$\%-(3)\_er%")

It should return records which has name start with text "test" but it will not instead of if I modify query like

SELECT * FROM (`abc`) WHERE (name LIKE "%test%\'!&@#$\%-(3)\_er%")

then it will give result. Why it is not give result with first query? Is there any other way to do this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
priyanka patel
  • 617
  • 2
  • 10
  • 30

2 Answers2

5

The % is the wildcard in the query.
So %test means everything that ends with test.
and test% means everything that begins with test.
and %test% means everything with test in it.

Simpy change your query to

SELECT * FROM (abc) WHERE (name LIKE "test%")

Rick Hoving
  • 3,585
  • 3
  • 29
  • 49
  • it is not work this SELECT `client_id` FROM (`client`) WHERE (client_name LIKE "%Client@$#%\'!&@#$\%-(3)\_er%") – priyanka patel Jan 10 '14 at 12:44
  • @priyanka patel SELECT client_id FROM (client) WHERE (client_name LIKE "_____%@$#%\'!&@#$\%-(3)_er%") – GOPI Jan 10 '14 at 12:47
0

If you want records that start with test, simply use

SELECT * FROM (`abc`) WHERE (name LIKE "test%")
Mad Dog Tannen
  • 7,129
  • 5
  • 31
  • 55