Compare two columns with 'LIKE' Operator in SQL / Laravel The 2019 Stack Overflow Developer Survey Results Are InAdd a column with a default value to an existing table in SQL ServerSQL select join: is it possible to prefix all columns as 'prefix.*'?SQLite - UPSERT *not* INSERT or REPLACESQL Server query - Selecting COUNT(*) with DISTINCTSQL Server: How to Join to first rowFind all tables containing column with specified name - MS SQL ServerHow to DROP multiple columns with a single ALTER TABLE statement in SQL Server?SQL select only rows with max value on a columnBest practices for SQL varchar column lengthSQL how to compare two columns from two different tables
Apparent duplicates between Haynes service instructions and MOT
Shouldn't "much" here be used instead of "more"?
Are spiders unable to hurt humans, especially very small spiders?
Protecting Dualbooting Windows from dangerous code (like rm -rf)
Why isn't the circumferential light around the M87 black hole's event horizon symmetric?
How come people say “Would of”?
Is there any way to tell whether the shot is going to hit you or not?
Why hard-Brexiteers don't insist on a hard border to prevent illegal immigration after Brexit?
Is this app Icon Browser Safe/Legit?
Can one be advised by a professor who is very far away?
Is flight data recorder erased after every flight?
Right tool to dig six foot holes?
Did 3000BC Egyptians use meteoric iron weapons?
Did Section 31 appear in Star Trek: The Next Generation?
If a Druid sees an animal’s corpse, can they wild shape into that animal?
How to notate time signature switching consistently every measure
How to save as into a customized destination on macOS?
Is an up-to-date browser secure on an out-of-date OS?
Delete all lines which don't have n characters before delimiter
What does Linus Torvalds mean when he says that Git "never ever" tracks a file?
Identify boardgame from Big movie
Return to UK after being refused entry years previously
When should I buy a clipper card after flying to OAK?
How to manage monthly salary
Compare two columns with 'LIKE' Operator in SQL / Laravel
The 2019 Stack Overflow Developer Survey Results Are InAdd a column with a default value to an existing table in SQL ServerSQL select join: is it possible to prefix all columns as 'prefix.*'?SQLite - UPSERT *not* INSERT or REPLACESQL Server query - Selecting COUNT(*) with DISTINCTSQL Server: How to Join to first rowFind all tables containing column with specified name - MS SQL ServerHow to DROP multiple columns with a single ALTER TABLE statement in SQL Server?SQL select only rows with max value on a columnBest practices for SQL varchar column lengthSQL how to compare two columns from two different tables
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to compare two columns from a table. In which i have to check the email is containing his mobile number or not.
TableName:- Table1
TableColumns:- id,email,MOB
Ex.
SQL:
'SELECT * FROM Tabel1 WHERE email LIKE %MOB%'
Laravel :
Tabel1::whereColumn('email', 'LIKE','%MOB%')->get();
I have Tried this above query but it is showing syntax error.
sql laravel
add a comment |
I'm trying to compare two columns from a table. In which i have to check the email is containing his mobile number or not.
TableName:- Table1
TableColumns:- id,email,MOB
Ex.
SQL:
'SELECT * FROM Tabel1 WHERE email LIKE %MOB%'
Laravel :
Tabel1::whereColumn('email', 'LIKE','%MOB%')->get();
I have Tried this above query but it is showing syntax error.
sql laravel
1
Whats is the error code?
– Bulfaitelo
Mar 8 at 9:47
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%' at line 1
– Biki mallik
Mar 8 at 9:58
add a comment |
I'm trying to compare two columns from a table. In which i have to check the email is containing his mobile number or not.
TableName:- Table1
TableColumns:- id,email,MOB
Ex.
SQL:
'SELECT * FROM Tabel1 WHERE email LIKE %MOB%'
Laravel :
Tabel1::whereColumn('email', 'LIKE','%MOB%')->get();
I have Tried this above query but it is showing syntax error.
sql laravel
I'm trying to compare two columns from a table. In which i have to check the email is containing his mobile number or not.
TableName:- Table1
TableColumns:- id,email,MOB
Ex.
SQL:
'SELECT * FROM Tabel1 WHERE email LIKE %MOB%'
Laravel :
Tabel1::whereColumn('email', 'LIKE','%MOB%')->get();
I have Tried this above query but it is showing syntax error.
sql laravel
sql laravel
edited Mar 8 at 9:42
Narendra
1,1781418
1,1781418
asked Mar 8 at 9:37
Biki mallikBiki mallik
2217
2217
1
Whats is the error code?
– Bulfaitelo
Mar 8 at 9:47
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%' at line 1
– Biki mallik
Mar 8 at 9:58
add a comment |
1
Whats is the error code?
– Bulfaitelo
Mar 8 at 9:47
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%' at line 1
– Biki mallik
Mar 8 at 9:58
1
1
Whats is the error code?
– Bulfaitelo
Mar 8 at 9:47
Whats is the error code?
– Bulfaitelo
Mar 8 at 9:47
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%' at line 1
– Biki mallik
Mar 8 at 9:58
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%' at line 1
– Biki mallik
Mar 8 at 9:58
add a comment |
3 Answers
3
active
oldest
votes
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, '%')"));
add a comment |
You should try this
SELECT * FROM Tabel1 WHERE email LIKE '%' +MOB+'%'
No . It is also showing Error.
– Biki mallik
Mar 8 at 10:28
Please consider adding a little more details for why you think your answer can help OP
– Black Mamba
Mar 8 at 14:03
add a comment |
SELECT * FROM `table` WHERE `email` LIKE '%MOB%';
IN '%MOB%' , MOB will be considered as string not the Column.
– Biki mallik
Mar 9 at 8:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060404%2fcompare-two-columns-with-like-operator-in-sql-laravel%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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, '%')"));
add a comment |
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, '%')"));
add a comment |
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, '%')"));
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, '%')"));
edited Mar 8 at 11:21
Namoshek
3,2272920
3,2272920
answered Mar 8 at 9:46
iatanasoviatanasov
1014
1014
add a comment |
add a comment |
You should try this
SELECT * FROM Tabel1 WHERE email LIKE '%' +MOB+'%'
No . It is also showing Error.
– Biki mallik
Mar 8 at 10:28
Please consider adding a little more details for why you think your answer can help OP
– Black Mamba
Mar 8 at 14:03
add a comment |
You should try this
SELECT * FROM Tabel1 WHERE email LIKE '%' +MOB+'%'
No . It is also showing Error.
– Biki mallik
Mar 8 at 10:28
Please consider adding a little more details for why you think your answer can help OP
– Black Mamba
Mar 8 at 14:03
add a comment |
You should try this
SELECT * FROM Tabel1 WHERE email LIKE '%' +MOB+'%'
You should try this
SELECT * FROM Tabel1 WHERE email LIKE '%' +MOB+'%'
edited Mar 8 at 10:00
Suraj Kumar
2,79841026
2,79841026
answered Mar 8 at 9:55
ajeetajeet
1
1
No . It is also showing Error.
– Biki mallik
Mar 8 at 10:28
Please consider adding a little more details for why you think your answer can help OP
– Black Mamba
Mar 8 at 14:03
add a comment |
No . It is also showing Error.
– Biki mallik
Mar 8 at 10:28
Please consider adding a little more details for why you think your answer can help OP
– Black Mamba
Mar 8 at 14:03
No . It is also showing Error.
– Biki mallik
Mar 8 at 10:28
No . It is also showing Error.
– Biki mallik
Mar 8 at 10:28
Please consider adding a little more details for why you think your answer can help OP
– Black Mamba
Mar 8 at 14:03
Please consider adding a little more details for why you think your answer can help OP
– Black Mamba
Mar 8 at 14:03
add a comment |
SELECT * FROM `table` WHERE `email` LIKE '%MOB%';
IN '%MOB%' , MOB will be considered as string not the Column.
– Biki mallik
Mar 9 at 8:59
add a comment |
SELECT * FROM `table` WHERE `email` LIKE '%MOB%';
IN '%MOB%' , MOB will be considered as string not the Column.
– Biki mallik
Mar 9 at 8:59
add a comment |
SELECT * FROM `table` WHERE `email` LIKE '%MOB%';
SELECT * FROM `table` WHERE `email` LIKE '%MOB%';
answered Mar 8 at 12:27
scode2704scode2704
515
515
IN '%MOB%' , MOB will be considered as string not the Column.
– Biki mallik
Mar 9 at 8:59
add a comment |
IN '%MOB%' , MOB will be considered as string not the Column.
– Biki mallik
Mar 9 at 8:59
IN '%MOB%' , MOB will be considered as string not the Column.
– Biki mallik
Mar 9 at 8:59
IN '%MOB%' , MOB will be considered as string not the Column.
– Biki mallik
Mar 9 at 8:59
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060404%2fcompare-two-columns-with-like-operator-in-sql-laravel%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Whats is the error code?
– Bulfaitelo
Mar 8 at 9:47
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%' at line 1
– Biki mallik
Mar 8 at 9:58