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;








0















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.










share|improve this question



















  • 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

















0















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.










share|improve this question



















  • 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













0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












3 Answers
3






active

oldest

votes


















1














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, '%')"));





share|improve this answer
































    0














    You should try this



    SELECT * FROM Tabel1 WHERE email LIKE '%' +MOB+'%'





    share|improve this answer

























    • 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


















    0














    SELECT * FROM `table` WHERE `email` LIKE '%MOB%';





    share|improve this answer























    • IN '%MOB%' , MOB will be considered as string not the Column.

      – Biki mallik
      Mar 9 at 8:59











    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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, '%')"));





    share|improve this answer





























      1














      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, '%')"));





      share|improve this answer



























        1












        1








        1







        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, '%')"));





        share|improve this answer















        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, '%')"));






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 8 at 11:21









        Namoshek

        3,2272920




        3,2272920










        answered Mar 8 at 9:46









        iatanasoviatanasov

        1014




        1014























            0














            You should try this



            SELECT * FROM Tabel1 WHERE email LIKE '%' +MOB+'%'





            share|improve this answer

























            • 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















            0














            You should try this



            SELECT * FROM Tabel1 WHERE email LIKE '%' +MOB+'%'





            share|improve this answer

























            • 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













            0












            0








            0







            You should try this



            SELECT * FROM Tabel1 WHERE email LIKE '%' +MOB+'%'





            share|improve this answer















            You should try this



            SELECT * FROM Tabel1 WHERE email LIKE '%' +MOB+'%'






            share|improve this answer














            share|improve this answer



            share|improve this answer








            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

















            • 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











            0














            SELECT * FROM `table` WHERE `email` LIKE '%MOB%';





            share|improve this answer























            • IN '%MOB%' , MOB will be considered as string not the Column.

              – Biki mallik
              Mar 9 at 8:59















            0














            SELECT * FROM `table` WHERE `email` LIKE '%MOB%';





            share|improve this answer























            • IN '%MOB%' , MOB will be considered as string not the Column.

              – Biki mallik
              Mar 9 at 8:59













            0












            0








            0







            SELECT * FROM `table` WHERE `email` LIKE '%MOB%';





            share|improve this answer













            SELECT * FROM `table` WHERE `email` LIKE '%MOB%';






            share|improve this answer












            share|improve this answer



            share|improve this answer










            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

















            • 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

















            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко