How to insert a field that contains a modified value of a rowCan I concatenate multiple MySQL rows into one field?Add Foreign Key to existing tablemysql syntax error 1064 at line 194 add foreign key for many-to-many relationshipVb.net error for query and databaseusing limit and where clause to make paginationLiquibase: How to set Charset UTF-8 on MySQL database tables?mysql relation slowhow to fetch menu from database with its subcategoryJOIN Query In MYSQL and PHP#1005 - Can't create table 'morina.#sql-3e25_35102' (errno: 150)

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

Why doesn't H₄O²⁺ exist?

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?

To string or not to string

Is it possible to do 50 km distance without any previous training?

Is a tag line useful on a cover?

Why not use SQL instead of GraphQL?

What do you call a Matrix-like slowdown and camera movement effect?

Why are electrically insulating heatsinks so rare? Is it just cost?

How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?

Finding angle with pure Geometry.

"to be prejudice towards/against someone" vs "to be prejudiced against/towards someone"

Can divisibility rules for digits be generalized to sum of digits

String Manipulation Interpreter

Why do I get two different answers for this counting problem?

Is it important to consider tone, melody, and musical form while writing a song?

How does strength of boric acid solution increase in presence of salicylic acid?

How to find program name(s) of an installed package?

Risk of getting Chronic Wasting Disease (CWD) in the United States?

US citizen flying to France today and my passport expires in less than 2 months

Test whether all array elements are factors of a number

How do I create uniquely male characters?

LaTeX closing $ signs makes cursor jump

Schoenfled Residua test shows proportionality hazard assumptions holds but Kaplan-Meier plots intersect



How to insert a field that contains a modified value of a row


Can I concatenate multiple MySQL rows into one field?Add Foreign Key to existing tablemysql syntax error 1064 at line 194 add foreign key for many-to-many relationshipVb.net error for query and databaseusing limit and where clause to make paginationLiquibase: How to set Charset UTF-8 on MySQL database tables?mysql relation slowhow to fetch menu from database with its subcategoryJOIN Query In MYSQL and PHP#1005 - Can't create table 'morina.#sql-3e25_35102' (errno: 150)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have this table:



CREATE TABLE `new_random` (
`i_domain` varchar(500) DEFAULT NULL,
`i_domain_no_http` varchar(500) DEFAULT NULL,
UNIQUE KEY `i_domain_UNIQUE` (`i_domain`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1


I have created the field i_domain_no_http using alter table. It is a new column (no value there it is initial set to NULL) where I want to insert the exact values of i_domain but after modifying them and removing a prefix http://./



I made the query:



insert into `myscheme`.`new_random` (`new_random`.`i_domain_no_http`)
select substring_index(`new_random`.`i_domain`,'http://',-1)
from `myscheme`.`new_random`;


Example, the table should look like:



i_domain | i_domain_no_http
------------------------------------
http://11.com | 11.com
https://22.com | 22.com


But I am getting this error:



i_domain | i_domain_no_http
------------------------------------
http://11.com |
https://22.com |
NULL | 11.com
NULL | 22.com


The 'i_domain' should be a primary key and not NULL but I had to remove the NN and PK to avoid the error:



Error Code: 1364. Field 'i_domain' doesn't have a default value


What is the problem? How to solve it?










share|improve this question






























    0















    I have this table:



    CREATE TABLE `new_random` (
    `i_domain` varchar(500) DEFAULT NULL,
    `i_domain_no_http` varchar(500) DEFAULT NULL,
    UNIQUE KEY `i_domain_UNIQUE` (`i_domain`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1


    I have created the field i_domain_no_http using alter table. It is a new column (no value there it is initial set to NULL) where I want to insert the exact values of i_domain but after modifying them and removing a prefix http://./



    I made the query:



    insert into `myscheme`.`new_random` (`new_random`.`i_domain_no_http`)
    select substring_index(`new_random`.`i_domain`,'http://',-1)
    from `myscheme`.`new_random`;


    Example, the table should look like:



    i_domain | i_domain_no_http
    ------------------------------------
    http://11.com | 11.com
    https://22.com | 22.com


    But I am getting this error:



    i_domain | i_domain_no_http
    ------------------------------------
    http://11.com |
    https://22.com |
    NULL | 11.com
    NULL | 22.com


    The 'i_domain' should be a primary key and not NULL but I had to remove the NN and PK to avoid the error:



    Error Code: 1364. Field 'i_domain' doesn't have a default value


    What is the problem? How to solve it?










    share|improve this question


























      0












      0








      0








      I have this table:



      CREATE TABLE `new_random` (
      `i_domain` varchar(500) DEFAULT NULL,
      `i_domain_no_http` varchar(500) DEFAULT NULL,
      UNIQUE KEY `i_domain_UNIQUE` (`i_domain`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1


      I have created the field i_domain_no_http using alter table. It is a new column (no value there it is initial set to NULL) where I want to insert the exact values of i_domain but after modifying them and removing a prefix http://./



      I made the query:



      insert into `myscheme`.`new_random` (`new_random`.`i_domain_no_http`)
      select substring_index(`new_random`.`i_domain`,'http://',-1)
      from `myscheme`.`new_random`;


      Example, the table should look like:



      i_domain | i_domain_no_http
      ------------------------------------
      http://11.com | 11.com
      https://22.com | 22.com


      But I am getting this error:



      i_domain | i_domain_no_http
      ------------------------------------
      http://11.com |
      https://22.com |
      NULL | 11.com
      NULL | 22.com


      The 'i_domain' should be a primary key and not NULL but I had to remove the NN and PK to avoid the error:



      Error Code: 1364. Field 'i_domain' doesn't have a default value


      What is the problem? How to solve it?










      share|improve this question
















      I have this table:



      CREATE TABLE `new_random` (
      `i_domain` varchar(500) DEFAULT NULL,
      `i_domain_no_http` varchar(500) DEFAULT NULL,
      UNIQUE KEY `i_domain_UNIQUE` (`i_domain`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1


      I have created the field i_domain_no_http using alter table. It is a new column (no value there it is initial set to NULL) where I want to insert the exact values of i_domain but after modifying them and removing a prefix http://./



      I made the query:



      insert into `myscheme`.`new_random` (`new_random`.`i_domain_no_http`)
      select substring_index(`new_random`.`i_domain`,'http://',-1)
      from `myscheme`.`new_random`;


      Example, the table should look like:



      i_domain | i_domain_no_http
      ------------------------------------
      http://11.com | 11.com
      https://22.com | 22.com


      But I am getting this error:



      i_domain | i_domain_no_http
      ------------------------------------
      http://11.com |
      https://22.com |
      NULL | 11.com
      NULL | 22.com


      The 'i_domain' should be a primary key and not NULL but I had to remove the NN and PK to avoid the error:



      Error Code: 1364. Field 'i_domain' doesn't have a default value


      What is the problem? How to solve it?







      mysql sql-insert






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 7:31









      Shadow

      26.2k93046




      26.2k93046










      asked Mar 21 at 23:42









      user9371654user9371654

      464523




      464523






















          1 Answer
          1






          active

          oldest

          votes


















          0














          What you want is an UPDATE query:



          UPDATE myscheme.new_random 
          SET i_domain_no_http = SUBSTRING_INDEX(new_random.i_domain,'://',-1)


          Output:



          i_domain i_domain_no_http
          http://11.com 11.com
          https://22.com 22.com


          Demo on dbfiddle






          share|improve this answer























            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%2f55290825%2fhow-to-insert-a-field-that-contains-a-modified-value-of-a-row%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            What you want is an UPDATE query:



            UPDATE myscheme.new_random 
            SET i_domain_no_http = SUBSTRING_INDEX(new_random.i_domain,'://',-1)


            Output:



            i_domain i_domain_no_http
            http://11.com 11.com
            https://22.com 22.com


            Demo on dbfiddle






            share|improve this answer



























              0














              What you want is an UPDATE query:



              UPDATE myscheme.new_random 
              SET i_domain_no_http = SUBSTRING_INDEX(new_random.i_domain,'://',-1)


              Output:



              i_domain i_domain_no_http
              http://11.com 11.com
              https://22.com 22.com


              Demo on dbfiddle






              share|improve this answer

























                0












                0








                0







                What you want is an UPDATE query:



                UPDATE myscheme.new_random 
                SET i_domain_no_http = SUBSTRING_INDEX(new_random.i_domain,'://',-1)


                Output:



                i_domain i_domain_no_http
                http://11.com 11.com
                https://22.com 22.com


                Demo on dbfiddle






                share|improve this answer













                What you want is an UPDATE query:



                UPDATE myscheme.new_random 
                SET i_domain_no_http = SUBSTRING_INDEX(new_random.i_domain,'://',-1)


                Output:



                i_domain i_domain_no_http
                http://11.com 11.com
                https://22.com 22.com


                Demo on dbfiddle







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 21 at 23:48









                NickNick

                38.6k132443




                38.6k132443





























                    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%2f55290825%2fhow-to-insert-a-field-that-contains-a-modified-value-of-a-row%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript