Filepath comparsion in MySQL - mysql

I am executing a MySQL query
select *
from table
where filepath LIKE '/Videos/ABC-Copy.mp4'
but I am getting zero rows as a result even though an exact same value exists in filepath column...
I have also tried using "//" in the query but am getting zero rows as result.
What am I missing ?

When you are using like, it's common to use the '%' character. Otherwise you don't need like. You can just do an equal.
For example what your above query actually does is.
select * from table where filepath = '/Videos/ABC-Copy.mp4'
What you want is
select * from table where filepath LIKE '%/Videos/ABC-Copy.mp4'

try with % symbol..
select * from table where filepath LIKE '%/Videos/ABC-Copy.mp4'

Related

mysql match special character % from a text

I have to select all rows from a table where column (varchar) values contain '%' in the text.
I tried below query but failed to get correct result set.
SELECT * from TABLE where VALUE LIKE '%%%'
Above query gives all rows of the table.
Please help me to form a query to match '%' and get the correct results.
SELECT * FROM your_table
WHERE value LIKE '%\\%%'
SQLFiddle demo
Escape character worked for me.
SELECT * from TABLE where VALUE LIKE '%\%%'
This query gives me correct result set.

use of like statement with or in mysql

I am working on a table with name exp1, in this table there is a column named filename which contain data like exp_ara1.txt, exp_gma1.txt, exp_sly1.txt., exp_rcy1.txt, exp_thy1.txt
By using MySQL query I want to select only those rows which have filename either %ara% or %gma%.
I am using following command:
Select * from exp1 where filename LIKE ('%ara%' OR '%gm%');
but it is results
Your SQL query has been executed successfully.
MySQL returned an empty result set (i.e. zero rows).
Try this:
Select * from exp1 where filename LIKE ('%ara%') OR filename LIKE ('%gm%');
I think this is one of the best process as if you have more multiple words to put in like::
$sql = array('0'); // Stop errors when $words is empty
foreach($words as $word){
$sql[] = 'filename LIKE %'.$word.'%'
}
$sql = 'SELECT * FROM exp1 WHERE '.implode(" OR ", $sql);
Using REGEXP we can write a single term to match using an alternation:
SELECT *
FROM exp1
WHERE filename REGEXP '(.*ara.*)|(.*gm.*)'
In MySQL you don't have the option to use the CONTAINS function like in SQL Server or Oracle, which is what it looks like your trying to do.
SELECT *
FROM exp1
WHERE (filename LIKE ('%ara%') OR filename LIKE ('%gm%'));

mysql matching encrypted values

When I run a query like this:
SELECT * FROM table WHERE columnName = AES_ENCRYPT('value','SecretKey')
I'm returned an empty set, even though there are rows in the db that match the search query.
What would the correct syntax for something like this look like?
SELECT * FROM table WHERE columnName = AES_ENCRYPT(columnName,'SecretKey')='value'

select command in mysql returns an empty row even though the entry exist in table

When I run the below query in phpmyadmin it returs 0 rows even the entry exists on the table
SELECT * FROM `default_companyshare` WHERE `comp_symbol` = "ACEDBL"
Try this in case you have some space-padding in your database:
SELECT * FROM `default_companyshare` WHERE `comp_symbol` like "%ACEDBL%"
You can also try trimming your result:
SELECT * FROM `default_companyshare` WHERE trim(`comp_symbol`) = "ACEDBL"
You clearly have some issue with the string comparison. Start with:
SELECT *
FROM `default_companyshare`
WHERE upper(`comp_symbol`) like '%ACEDBL%';
This will show you all the symbols that contain that string. Then figure out if the problem is leading/trailing spaces, collation conflicts, hidden characters, or something else.

mysql like query with special character '

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?
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%")
If you want records that start with test, simply use
SELECT * FROM (`abc`) WHERE (name LIKE "test%")