Insert if NOT EXISTS not working Announcing the arrival of Valued Associate #679: Cesar...

Models of set theory where not every set can be linearly ordered

What makes black pepper strong or mild?

How to recreate this effect in Photoshop?

Did Kevin spill real chili?

What happens to sewage if there is no river near by?

How widely used is the term Treppenwitz? Is it something that most Germans know?

Does surprise arrest existing movement?

Is there a "higher Segal conjecture"?

Java 8 stream max() function argument type Comparator vs Comparable

Gastric acid as a weapon

What are the motives behind Cersei's orders given to Bronn?

Stars Make Stars

How do I mention the quality of my school without bragging

What is the longest distance a 13th-level monk can jump while attacking on the same turn?

Is there a concise way to say "all of the X, one of each"?

When to stop saving and start investing?

When -s is used with third person singular. What's its use in this context?

What are the pros and cons of Aerospike nosecones?

Should I call the interviewer directly, if HR aren't responding?

How much radiation do nuclear physics experiments expose researchers to nowadays?

Why are there no cargo aircraft with "flying wing" design?

Should I discuss the type of campaign with my players?

Storing hydrofluoric acid before the invention of plastics

Letter Boxed validator



Insert if NOT EXISTS not working



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)phpMyAdmin Error After Upgrade to 3.5.8.1Returning true or false in a custom functionFederated table of two LEFT JOIN tables not workingCreate Trigger MySql update or insert in another tableError in IF statement in MySQLDon't know why MySQL is not creating table with primary key constraintMySQL stored procedure returns nullWhy doesn't the following stored procedure compile with MySQL Workbench version 6.3.?Error 1064 - You have an error in your SQL syntax;Trying to run query and getting error: Error 1064 (42000)





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







2















I am trying to copy data from table to another mysql table from two different databases

First I get all data from first table and stored them into php variable

then I loop on that var to insert data to the other table

using this query



INSERT INTO `users` (`nUserId`, `vLoginName`, `vFirstName`, `vLastName`, `vEmail`)
VALUES ('$entity_id','$name','$firstname','$lastname','$email')
WHERE NOT EXISTS (SELECT `nUserId`,`vEmail`
FROM `users`
WHERE `nUserId`='$entity_id'
AND `vEmail` = '$email')


but it's not working



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 'WHERE NOT EXISTS (SELECT `nUserId`,`vEmail` FROM users ' 


What the correct syntax to make this work ?










share|improve this question





























    2















    I am trying to copy data from table to another mysql table from two different databases

    First I get all data from first table and stored them into php variable

    then I loop on that var to insert data to the other table

    using this query



    INSERT INTO `users` (`nUserId`, `vLoginName`, `vFirstName`, `vLastName`, `vEmail`)
    VALUES ('$entity_id','$name','$firstname','$lastname','$email')
    WHERE NOT EXISTS (SELECT `nUserId`,`vEmail`
    FROM `users`
    WHERE `nUserId`='$entity_id'
    AND `vEmail` = '$email')


    but it's not working



    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 'WHERE NOT EXISTS (SELECT `nUserId`,`vEmail` FROM users ' 


    What the correct syntax to make this work ?










    share|improve this question

























      2












      2








      2


      2






      I am trying to copy data from table to another mysql table from two different databases

      First I get all data from first table and stored them into php variable

      then I loop on that var to insert data to the other table

      using this query



      INSERT INTO `users` (`nUserId`, `vLoginName`, `vFirstName`, `vLastName`, `vEmail`)
      VALUES ('$entity_id','$name','$firstname','$lastname','$email')
      WHERE NOT EXISTS (SELECT `nUserId`,`vEmail`
      FROM `users`
      WHERE `nUserId`='$entity_id'
      AND `vEmail` = '$email')


      but it's not working



      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 'WHERE NOT EXISTS (SELECT `nUserId`,`vEmail` FROM users ' 


      What the correct syntax to make this work ?










      share|improve this question














      I am trying to copy data from table to another mysql table from two different databases

      First I get all data from first table and stored them into php variable

      then I loop on that var to insert data to the other table

      using this query



      INSERT INTO `users` (`nUserId`, `vLoginName`, `vFirstName`, `vLastName`, `vEmail`)
      VALUES ('$entity_id','$name','$firstname','$lastname','$email')
      WHERE NOT EXISTS (SELECT `nUserId`,`vEmail`
      FROM `users`
      WHERE `nUserId`='$entity_id'
      AND `vEmail` = '$email')


      but it's not working



      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 'WHERE NOT EXISTS (SELECT `nUserId`,`vEmail` FROM users ' 


      What the correct syntax to make this work ?







      mysql php






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 13 '15 at 15:26









      Ashraf HefnyAshraf Hefny

      13115




      13115






















          5 Answers
          5






          active

          oldest

          votes


















          1














          You cannot use WHERE clause in an INSERT statement.
          However, you may use INSERT IGNORE if in your targer table you define nUserId or vEmail as unique keys.



          More info about INSERT syntax: https://dev.mysql.com/doc/refman/5.6/en/insert.html






          share|improve this answer



















          • 1





            INSERT IGNORE can also have unwanted side effects in other cases (values not good for the columns, etc.) It may not be the best choice. In your link: "Data conversions that would trigger errors abort the statement if IGNORE is not specified. With IGNORE, invalid values are adjusted to the closest values and inserted; warnings are produced but the statement does not abort."

            – ypercubeᵀᴹ
            May 13 '15 at 15:53













          • @Jehad Keriaki Thanks man it's working now INSERT IGNORE INTO users` SET nUserId='$entity_id', vLoginName='$name', vFirstName='$firstname', vLastName='$lastname', vEmail='$email'`

            – Ashraf Hefny
            May 13 '15 at 15:59











          • As an advice, read my comment above and if you care for your data don't use INSERT IGNORE. Either use INSERT ... ON DUPLICATE KEY UPDATE or the query by @SQLHound.

            – ypercubeᵀᴹ
            May 13 '15 at 16:02













          • If you don't believe me, read this answer by Bill Karwin: “INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”

            – ypercubeᵀᴹ
            May 13 '15 at 16:05



















          2














          I think the problem might be VALUES and I would write the statement as the following:



          INSERT INTO `users` 
          (`nUserId`, `vLoginName`, `vFirstName`, `vLastName`, `vEmail`)
          SELECT
          '$entity_id', '$name', '$firstname', '$lastname', '$email'
          FROM dual
          WHERE NOT EXISTS (SELECT *
          FROM `users`
          WHERE `nUserId`='$entity_id'
          AND `vEmail` = '$email')





          share|improve this answer


























          • The solution.

            – Ring Ø
            Sep 19 '18 at 3:11



















          2














          you can try something like



          delimiter $$
          create procedure select_or_insert()
          begin
          IF EXISTS (select * from users where username = 'something') THEN
          update users set id= 'some' where username = 'something';
          ELSE
          insert into users (username) values ('something');
          END IF;
          end $$
          delimiter ;





          share|improve this answer
























          • Good solution: easy to understand and read

            – Julian
            Sep 12 '16 at 9:44



















          1














          No need to store them in php.



          Creates a table excactly like the one specified, Note: copies only columns



          CREATE TABLE tbl_name LIKE db_name.tbl_name;


          If you want specific column names:



          CREATE TABLE tbl_name SELECT column_name, column_name FROM db_name.tbl_name;


          Then if you want to copy all the data do



          INSERT INTO tbl_name SELECT * FROM db_name.tbl_name;


          Or specific column data do



          INSERT INTO tbl_name SELECT column_name, column_name FROM db_name.tbl_name;


          If you want specific data add a WHERE clause.






          share|improve this answer































            0














            $existeEmail=$mysqli->query("SELECT * FROM tb_users WHERE email = '$email'");
            if(!$existeEmail=mysqli_fetch_array($existeEmail))/si existe en la tabla tblreseteopass/
            {



            }else{
            $email = $existeEmail['email'];
            // Direccionado hacia el registro con la Alerta 001
            // ya existe una cuenta asociada a este email, si no recuerda la contraseña, solicite una nueva
            header("Location: https://www.yourpage.com/b/?m=f_lg);
            }





            share








            New contributor




            jorge mario saldarriaga r. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "182"
              };
              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: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              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%2fdba.stackexchange.com%2fquestions%2f101413%2finsert-if-not-exists-not-working%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              5 Answers
              5






              active

              oldest

              votes








              5 Answers
              5






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              You cannot use WHERE clause in an INSERT statement.
              However, you may use INSERT IGNORE if in your targer table you define nUserId or vEmail as unique keys.



              More info about INSERT syntax: https://dev.mysql.com/doc/refman/5.6/en/insert.html






              share|improve this answer



















              • 1





                INSERT IGNORE can also have unwanted side effects in other cases (values not good for the columns, etc.) It may not be the best choice. In your link: "Data conversions that would trigger errors abort the statement if IGNORE is not specified. With IGNORE, invalid values are adjusted to the closest values and inserted; warnings are produced but the statement does not abort."

                – ypercubeᵀᴹ
                May 13 '15 at 15:53













              • @Jehad Keriaki Thanks man it's working now INSERT IGNORE INTO users` SET nUserId='$entity_id', vLoginName='$name', vFirstName='$firstname', vLastName='$lastname', vEmail='$email'`

                – Ashraf Hefny
                May 13 '15 at 15:59











              • As an advice, read my comment above and if you care for your data don't use INSERT IGNORE. Either use INSERT ... ON DUPLICATE KEY UPDATE or the query by @SQLHound.

                – ypercubeᵀᴹ
                May 13 '15 at 16:02













              • If you don't believe me, read this answer by Bill Karwin: “INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”

                – ypercubeᵀᴹ
                May 13 '15 at 16:05
















              1














              You cannot use WHERE clause in an INSERT statement.
              However, you may use INSERT IGNORE if in your targer table you define nUserId or vEmail as unique keys.



              More info about INSERT syntax: https://dev.mysql.com/doc/refman/5.6/en/insert.html






              share|improve this answer



















              • 1





                INSERT IGNORE can also have unwanted side effects in other cases (values not good for the columns, etc.) It may not be the best choice. In your link: "Data conversions that would trigger errors abort the statement if IGNORE is not specified. With IGNORE, invalid values are adjusted to the closest values and inserted; warnings are produced but the statement does not abort."

                – ypercubeᵀᴹ
                May 13 '15 at 15:53













              • @Jehad Keriaki Thanks man it's working now INSERT IGNORE INTO users` SET nUserId='$entity_id', vLoginName='$name', vFirstName='$firstname', vLastName='$lastname', vEmail='$email'`

                – Ashraf Hefny
                May 13 '15 at 15:59











              • As an advice, read my comment above and if you care for your data don't use INSERT IGNORE. Either use INSERT ... ON DUPLICATE KEY UPDATE or the query by @SQLHound.

                – ypercubeᵀᴹ
                May 13 '15 at 16:02













              • If you don't believe me, read this answer by Bill Karwin: “INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”

                – ypercubeᵀᴹ
                May 13 '15 at 16:05














              1












              1








              1







              You cannot use WHERE clause in an INSERT statement.
              However, you may use INSERT IGNORE if in your targer table you define nUserId or vEmail as unique keys.



              More info about INSERT syntax: https://dev.mysql.com/doc/refman/5.6/en/insert.html






              share|improve this answer













              You cannot use WHERE clause in an INSERT statement.
              However, you may use INSERT IGNORE if in your targer table you define nUserId or vEmail as unique keys.



              More info about INSERT syntax: https://dev.mysql.com/doc/refman/5.6/en/insert.html







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered May 13 '15 at 15:35









              Jehad KeriakiJehad Keriaki

              2,6631813




              2,6631813








              • 1





                INSERT IGNORE can also have unwanted side effects in other cases (values not good for the columns, etc.) It may not be the best choice. In your link: "Data conversions that would trigger errors abort the statement if IGNORE is not specified. With IGNORE, invalid values are adjusted to the closest values and inserted; warnings are produced but the statement does not abort."

                – ypercubeᵀᴹ
                May 13 '15 at 15:53













              • @Jehad Keriaki Thanks man it's working now INSERT IGNORE INTO users` SET nUserId='$entity_id', vLoginName='$name', vFirstName='$firstname', vLastName='$lastname', vEmail='$email'`

                – Ashraf Hefny
                May 13 '15 at 15:59











              • As an advice, read my comment above and if you care for your data don't use INSERT IGNORE. Either use INSERT ... ON DUPLICATE KEY UPDATE or the query by @SQLHound.

                – ypercubeᵀᴹ
                May 13 '15 at 16:02













              • If you don't believe me, read this answer by Bill Karwin: “INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”

                – ypercubeᵀᴹ
                May 13 '15 at 16:05














              • 1





                INSERT IGNORE can also have unwanted side effects in other cases (values not good for the columns, etc.) It may not be the best choice. In your link: "Data conversions that would trigger errors abort the statement if IGNORE is not specified. With IGNORE, invalid values are adjusted to the closest values and inserted; warnings are produced but the statement does not abort."

                – ypercubeᵀᴹ
                May 13 '15 at 15:53













              • @Jehad Keriaki Thanks man it's working now INSERT IGNORE INTO users` SET nUserId='$entity_id', vLoginName='$name', vFirstName='$firstname', vLastName='$lastname', vEmail='$email'`

                – Ashraf Hefny
                May 13 '15 at 15:59











              • As an advice, read my comment above and if you care for your data don't use INSERT IGNORE. Either use INSERT ... ON DUPLICATE KEY UPDATE or the query by @SQLHound.

                – ypercubeᵀᴹ
                May 13 '15 at 16:02













              • If you don't believe me, read this answer by Bill Karwin: “INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”

                – ypercubeᵀᴹ
                May 13 '15 at 16:05








              1




              1





              INSERT IGNORE can also have unwanted side effects in other cases (values not good for the columns, etc.) It may not be the best choice. In your link: "Data conversions that would trigger errors abort the statement if IGNORE is not specified. With IGNORE, invalid values are adjusted to the closest values and inserted; warnings are produced but the statement does not abort."

              – ypercubeᵀᴹ
              May 13 '15 at 15:53







              INSERT IGNORE can also have unwanted side effects in other cases (values not good for the columns, etc.) It may not be the best choice. In your link: "Data conversions that would trigger errors abort the statement if IGNORE is not specified. With IGNORE, invalid values are adjusted to the closest values and inserted; warnings are produced but the statement does not abort."

              – ypercubeᵀᴹ
              May 13 '15 at 15:53















              @Jehad Keriaki Thanks man it's working now INSERT IGNORE INTO users` SET nUserId='$entity_id', vLoginName='$name', vFirstName='$firstname', vLastName='$lastname', vEmail='$email'`

              – Ashraf Hefny
              May 13 '15 at 15:59





              @Jehad Keriaki Thanks man it's working now INSERT IGNORE INTO users` SET nUserId='$entity_id', vLoginName='$name', vFirstName='$firstname', vLastName='$lastname', vEmail='$email'`

              – Ashraf Hefny
              May 13 '15 at 15:59













              As an advice, read my comment above and if you care for your data don't use INSERT IGNORE. Either use INSERT ... ON DUPLICATE KEY UPDATE or the query by @SQLHound.

              – ypercubeᵀᴹ
              May 13 '15 at 16:02







              As an advice, read my comment above and if you care for your data don't use INSERT IGNORE. Either use INSERT ... ON DUPLICATE KEY UPDATE or the query by @SQLHound.

              – ypercubeᵀᴹ
              May 13 '15 at 16:02















              If you don't believe me, read this answer by Bill Karwin: “INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”

              – ypercubeᵀᴹ
              May 13 '15 at 16:05





              If you don't believe me, read this answer by Bill Karwin: “INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”

              – ypercubeᵀᴹ
              May 13 '15 at 16:05













              2














              I think the problem might be VALUES and I would write the statement as the following:



              INSERT INTO `users` 
              (`nUserId`, `vLoginName`, `vFirstName`, `vLastName`, `vEmail`)
              SELECT
              '$entity_id', '$name', '$firstname', '$lastname', '$email'
              FROM dual
              WHERE NOT EXISTS (SELECT *
              FROM `users`
              WHERE `nUserId`='$entity_id'
              AND `vEmail` = '$email')





              share|improve this answer


























              • The solution.

                – Ring Ø
                Sep 19 '18 at 3:11
















              2














              I think the problem might be VALUES and I would write the statement as the following:



              INSERT INTO `users` 
              (`nUserId`, `vLoginName`, `vFirstName`, `vLastName`, `vEmail`)
              SELECT
              '$entity_id', '$name', '$firstname', '$lastname', '$email'
              FROM dual
              WHERE NOT EXISTS (SELECT *
              FROM `users`
              WHERE `nUserId`='$entity_id'
              AND `vEmail` = '$email')





              share|improve this answer


























              • The solution.

                – Ring Ø
                Sep 19 '18 at 3:11














              2












              2








              2







              I think the problem might be VALUES and I would write the statement as the following:



              INSERT INTO `users` 
              (`nUserId`, `vLoginName`, `vFirstName`, `vLastName`, `vEmail`)
              SELECT
              '$entity_id', '$name', '$firstname', '$lastname', '$email'
              FROM dual
              WHERE NOT EXISTS (SELECT *
              FROM `users`
              WHERE `nUserId`='$entity_id'
              AND `vEmail` = '$email')





              share|improve this answer















              I think the problem might be VALUES and I would write the statement as the following:



              INSERT INTO `users` 
              (`nUserId`, `vLoginName`, `vFirstName`, `vLastName`, `vEmail`)
              SELECT
              '$entity_id', '$name', '$firstname', '$lastname', '$email'
              FROM dual
              WHERE NOT EXISTS (SELECT *
              FROM `users`
              WHERE `nUserId`='$entity_id'
              AND `vEmail` = '$email')






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 13 '15 at 15:46









              ypercubeᵀᴹ

              78.6k11137221




              78.6k11137221










              answered May 13 '15 at 15:44









              SQLHoundSQLHound

              251213




              251213













              • The solution.

                – Ring Ø
                Sep 19 '18 at 3:11



















              • The solution.

                – Ring Ø
                Sep 19 '18 at 3:11

















              The solution.

              – Ring Ø
              Sep 19 '18 at 3:11





              The solution.

              – Ring Ø
              Sep 19 '18 at 3:11











              2














              you can try something like



              delimiter $$
              create procedure select_or_insert()
              begin
              IF EXISTS (select * from users where username = 'something') THEN
              update users set id= 'some' where username = 'something';
              ELSE
              insert into users (username) values ('something');
              END IF;
              end $$
              delimiter ;





              share|improve this answer
























              • Good solution: easy to understand and read

                – Julian
                Sep 12 '16 at 9:44
















              2














              you can try something like



              delimiter $$
              create procedure select_or_insert()
              begin
              IF EXISTS (select * from users where username = 'something') THEN
              update users set id= 'some' where username = 'something';
              ELSE
              insert into users (username) values ('something');
              END IF;
              end $$
              delimiter ;





              share|improve this answer
























              • Good solution: easy to understand and read

                – Julian
                Sep 12 '16 at 9:44














              2












              2








              2







              you can try something like



              delimiter $$
              create procedure select_or_insert()
              begin
              IF EXISTS (select * from users where username = 'something') THEN
              update users set id= 'some' where username = 'something';
              ELSE
              insert into users (username) values ('something');
              END IF;
              end $$
              delimiter ;





              share|improve this answer













              you can try something like



              delimiter $$
              create procedure select_or_insert()
              begin
              IF EXISTS (select * from users where username = 'something') THEN
              update users set id= 'some' where username = 'something';
              ELSE
              insert into users (username) values ('something');
              END IF;
              end $$
              delimiter ;






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered May 13 '15 at 16:17









              Bill N. VarelliBill N. Varelli

              5091417




              5091417













              • Good solution: easy to understand and read

                – Julian
                Sep 12 '16 at 9:44



















              • Good solution: easy to understand and read

                – Julian
                Sep 12 '16 at 9:44

















              Good solution: easy to understand and read

              – Julian
              Sep 12 '16 at 9:44





              Good solution: easy to understand and read

              – Julian
              Sep 12 '16 at 9:44











              1














              No need to store them in php.



              Creates a table excactly like the one specified, Note: copies only columns



              CREATE TABLE tbl_name LIKE db_name.tbl_name;


              If you want specific column names:



              CREATE TABLE tbl_name SELECT column_name, column_name FROM db_name.tbl_name;


              Then if you want to copy all the data do



              INSERT INTO tbl_name SELECT * FROM db_name.tbl_name;


              Or specific column data do



              INSERT INTO tbl_name SELECT column_name, column_name FROM db_name.tbl_name;


              If you want specific data add a WHERE clause.






              share|improve this answer




























                1














                No need to store them in php.



                Creates a table excactly like the one specified, Note: copies only columns



                CREATE TABLE tbl_name LIKE db_name.tbl_name;


                If you want specific column names:



                CREATE TABLE tbl_name SELECT column_name, column_name FROM db_name.tbl_name;


                Then if you want to copy all the data do



                INSERT INTO tbl_name SELECT * FROM db_name.tbl_name;


                Or specific column data do



                INSERT INTO tbl_name SELECT column_name, column_name FROM db_name.tbl_name;


                If you want specific data add a WHERE clause.






                share|improve this answer


























                  1












                  1








                  1







                  No need to store them in php.



                  Creates a table excactly like the one specified, Note: copies only columns



                  CREATE TABLE tbl_name LIKE db_name.tbl_name;


                  If you want specific column names:



                  CREATE TABLE tbl_name SELECT column_name, column_name FROM db_name.tbl_name;


                  Then if you want to copy all the data do



                  INSERT INTO tbl_name SELECT * FROM db_name.tbl_name;


                  Or specific column data do



                  INSERT INTO tbl_name SELECT column_name, column_name FROM db_name.tbl_name;


                  If you want specific data add a WHERE clause.






                  share|improve this answer













                  No need to store them in php.



                  Creates a table excactly like the one specified, Note: copies only columns



                  CREATE TABLE tbl_name LIKE db_name.tbl_name;


                  If you want specific column names:



                  CREATE TABLE tbl_name SELECT column_name, column_name FROM db_name.tbl_name;


                  Then if you want to copy all the data do



                  INSERT INTO tbl_name SELECT * FROM db_name.tbl_name;


                  Or specific column data do



                  INSERT INTO tbl_name SELECT column_name, column_name FROM db_name.tbl_name;


                  If you want specific data add a WHERE clause.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 15 '16 at 13:25









                  Martin CzechMartin Czech

                  112




                  112























                      0














                      $existeEmail=$mysqli->query("SELECT * FROM tb_users WHERE email = '$email'");
                      if(!$existeEmail=mysqli_fetch_array($existeEmail))/si existe en la tabla tblreseteopass/
                      {



                      }else{
                      $email = $existeEmail['email'];
                      // Direccionado hacia el registro con la Alerta 001
                      // ya existe una cuenta asociada a este email, si no recuerda la contraseña, solicite una nueva
                      header("Location: https://www.yourpage.com/b/?m=f_lg);
                      }





                      share








                      New contributor




                      jorge mario saldarriaga r. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

























                        0














                        $existeEmail=$mysqli->query("SELECT * FROM tb_users WHERE email = '$email'");
                        if(!$existeEmail=mysqli_fetch_array($existeEmail))/si existe en la tabla tblreseteopass/
                        {



                        }else{
                        $email = $existeEmail['email'];
                        // Direccionado hacia el registro con la Alerta 001
                        // ya existe una cuenta asociada a este email, si no recuerda la contraseña, solicite una nueva
                        header("Location: https://www.yourpage.com/b/?m=f_lg);
                        }





                        share








                        New contributor




                        jorge mario saldarriaga r. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.























                          0












                          0








                          0







                          $existeEmail=$mysqli->query("SELECT * FROM tb_users WHERE email = '$email'");
                          if(!$existeEmail=mysqli_fetch_array($existeEmail))/si existe en la tabla tblreseteopass/
                          {



                          }else{
                          $email = $existeEmail['email'];
                          // Direccionado hacia el registro con la Alerta 001
                          // ya existe una cuenta asociada a este email, si no recuerda la contraseña, solicite una nueva
                          header("Location: https://www.yourpage.com/b/?m=f_lg);
                          }





                          share








                          New contributor




                          jorge mario saldarriaga r. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          $existeEmail=$mysqli->query("SELECT * FROM tb_users WHERE email = '$email'");
                          if(!$existeEmail=mysqli_fetch_array($existeEmail))/si existe en la tabla tblreseteopass/
                          {



                          }else{
                          $email = $existeEmail['email'];
                          // Direccionado hacia el registro con la Alerta 001
                          // ya existe una cuenta asociada a este email, si no recuerda la contraseña, solicite una nueva
                          header("Location: https://www.yourpage.com/b/?m=f_lg);
                          }






                          share








                          New contributor




                          jorge mario saldarriaga r. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.








                          share


                          share






                          New contributor




                          jorge mario saldarriaga r. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 1 min ago









                          jorge mario saldarriaga r.jorge mario saldarriaga r.

                          1




                          1




                          New contributor




                          jorge mario saldarriaga r. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          jorge mario saldarriaga r. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          jorge mario saldarriaga r. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Database Administrators Stack Exchange!


                              • 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%2fdba.stackexchange.com%2fquestions%2f101413%2finsert-if-not-exists-not-working%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

                              Anexo:Material bélico de la Fuerza Aérea de Chile Índice Aeronaves Defensa...

                              Always On Availability groups resolving state after failover - Remote harden of transaction...

                              update json value to null Announcing the arrival of Valued Associate #679: Cesar Manara ...