Can I use 'like' to compare to a field in another table?
Remove the quotes from 'mask'. You don't want the STRING of mask, you want the VALUE of mask. I also changed the & to a + since my SQL Server (2012) doesn't allow the & for nvarchar data types.
SELECT FileName FROM tFiles
WHERE FileName not in
(SELECT FileName from tFiles, tMasks where FileName like (mask + '%'));
I set up your described scenario on my database and it returned two rows:
FileName
aut_cnty
exvndata00
Good luck!
MySQL - How to use fields in 'LIKE' operator
SELECT field1, field2
FROM table
WHERE field2 LIKE CONCAT('%', field1, '%');
Compare two columns with 'LIKE' Operator in SQL / Laravel
Lets start by answering you question SQL-wise, anything in quotes is a literal to SQL, so you need to use column reference and add the wildcard symbols. You can do that like this:
SELECT * FROM Table1 WHERE email LIKE CONCAT('%', MOB, '%');
Now lets look at Laravel now, the 3rd argument to where expects a literal value not another column. You can overcome this via either whereRaw or DB::raw:
Table1::whereRaw("email LIKE CONCAT('%', MOB, '%')");
or
Table1::where('email', 'LIKE', DB::raw("CONCAT('%', MOB, '%')"));
Compare Columns Where One is Similar to Part of Another
Reverse the where, to something like this:
Fullname not like '%' + FirstName + '%'
How to compare one field of a table with another field in a different table using like
You need to swap the search columns. See Pattern Matching
SELECT domain
FROM domains, keywords
WHERE domain like concat('%',keyword,'%');
e.g.
SELECT 'www.dailyshop.com' LIKE CONCAT('%','shop','%');
+-------------------------------------------------+
| 'www.dailyshop.com' LIKE CONCAT('%','shop','%') |
+-------------------------------------------------+
| 1 |
+-------------------------------------------------+
Related Topics
Sql Join: Selecting the Last Records in a One-To-Many Relationship
How to Get a List of Column Names on Sqlite3 Database
Retrieve Varbinary Value as Base64 in Mssql
Disable Secure Priv for Data Loading on MySQL
Convert Utc Milliseconds to Datetime in SQL Server
Best Way to Iterate Through Columns in a SQL Table
Mysql - Left Join Takes Too Long, How to Optimize Query
Regex to Filter for Numers With and Without Dots
How to Sum Up Time Field in SQL Server
Sql 0 Results for 'Not In' and 'In' When Row Does Exist
Sql Query to Select Million Records Quickly
How to Select Three Table With Same Column Name But Different Values
Retrieve String Between HTML Tags Using Regex
Mysql - Trigger for Updating Same Table After Insert
Subtraction Between Two SQL Queries
Selecting First and Last Values in a Group
Removing Null Value in SQL Join and Union Operators in SQL
Replace Null Value With Previous Available Value in Row SQL Server Query