MySQL: What is a reverse version of LIKE?
Here's a way you can achieve what you describe:
SELECT name FROM user
WHERE 'John Smith and Peter Johnson are best friends' LIKE
CONCAT('%', name, '%')
MySql LIKE in reverse?
Use LIKE
with your column surrounded by wildcards:
SELECT *
FROM books
WHERE 'Harry Potter' LIKE CONCAT('%', titles, '%')
If you have a long term need for such searches, you might want to look into using MySQL's full text search capabilities.
Mysql like search in reverse
SELECT *
FROM tableName
WHERE 'the animal is a fox' LIKE CONCAT('%', animal ,'%')
- SQLFiddle Demo
Reverse version of sql LIKE in sqlalchemy
Thanks to this question, I figure out how to do that :)
session.query(Book).
filter(bindparam('book_title', book.title).contains(Book.title)).first()
MySql LIKE in reverse?
Use LIKE
with your column surrounded by wildcards:
SELECT *
FROM books
WHERE 'Harry Potter' LIKE CONCAT('%', titles, '%')
If you have a long term need for such searches, you might want to look into using MySQL's full text search capabilities.
MySQL question about reverse LIKEs
You can reverse a like
statement. Just using the same syntax as a regular like
query:
select
*
from
table
where
'value' like concat('%', column, '%')
Of course, if you felt wild and crazy, you could also use instr
:
select * from table where instr('value', column) > 0
I don't know which one is faster, since I don't have a MySQL instance to test against, but it's worth trying both to see which wins.
MySql Reverse LIKE clause
I think you are looking for CONCAT
syntax
mysql_query("SELECT id FROM urls WHERE '".$url."' LIKE CONCAT('%', domain, '%')")or die(mysql_error());
and then you can check if the query returned any result or not.
inversed use of like withquery builder
Try this:
$qb->expr()
->like(
':advertLieu',
$qb->expr()
->concat(
$qb->expr()->literal('%'),
$qb->expr()->concat('a.lieu', $qb->expr()->literal('%'))
)
);
->setParameter('advertLieu', $postedAdvert->getVille()->getName())
For your update I would suggest you do this:
$qb->expr()->in('u.id', ':ids');
->setParameter('ids', $id)
Optimise Reverse LIKE query in mysql
Change the query to:
SELECT number
FROM table
WHERE number IN ('1', '12', '123', '1234', '12345', '123456', '1234567', '12345679')
and create an index on number
.
If you're performing the query from a programming language, it should be able to create the IN
list dynamically using a loop on the input string. If you're doing it entirely in MySQL, you can do it in a stored procedure.
Reverse query with like - laravel eloquent or raw MySQL query
Probably you can use not like
operator in this case:
$object = Related::whereHas( function($q)
{
$q->where('URL', 'not like', 'http%');
)->get();
Related Topics
Mysql's Alternative to T-Sql's with Ties
How to Get the First and Last Date of the Current Year
How to Include Null Values in a Min or Max
Convert a String Date into Datetime in Oracle
Passing Table and Column Name Dynamically Using Bind Variables
Which Is Better: Ad Hoc Queries or Stored Procedures
How to Get the Last Row of an Oracle Table
How to Calculate a Running Total in SQL Without Using a Cursor
Dynamic Pivot Table in SQL Server
How to Make a Composite Key with SQL Server Management Studio
Database Eav Pros/Cons and Alternatives
Select Only Rows by Join Tables Max Value
How to Scale Pivoting in Bigquery
Eliminating Duplicate Values Based on Only One Column of the Table
Execute Immediate Within a Stored Procedure Keeps Giving Insufficient Priviliges Error
How to Select Id with Max Date Group by Category in Postgresql
Need to List All Triggers in SQL Server Database with Table Name and Table's Schema