csharpcoder csharpcoder -4 years ago 79
SQL Question

working with special character forward slash '\' or backward slash '/' in MySQL

I am storing the full-path details of the file in a table with its name and Id assigned to it.
Now for retrieving the row on the query below

select *
from path_table
where path = 'D:\\\WorkBench\\\Demo\\\sample.txt'


This is working fine .

How can I get the same result with 'like' in MySQL

select *
from path_table
where path like 'D:\\\WorkBench\\Demo\\\sample.txt'


This statement returns 0 rows.
Actually I need something like if I give

select *
from path_table
where path like 'D:\\\WorkBench\\\Demo\\\'


It should return all rows I.e. files under same path so need to use like with '%'. But its not working. What should I use instead?

Answer Source

try this query:

select * from path_table where path like '%D:\\WorkBench\\Demo\\%'

You forgot to put this sign (%) in the starting and ending.

note:I put % sign in the starting also because may be there were some characters added in the db.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download