How to move then delete field in MySQL

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to move then delete field in MySQL



I am trying to move a field from one table to another and then delete it from the first table. The problem I am having is that it moves the data fine, but it is not deleting it from the first table.



Here is my code:


"INSERT INTO out_tickets SELECT * FROM tickets";
"DELETE FROM tickets WHERE * FROM tickets";



Not sure what I am doing wrong?



EDIT



Updated Code:


<?php
// Process delete operation after confirmation
if(isset($_POST["id"]) && !empty($_POST["id"])){
// Include config file
require_once 'config.php';

// Prepare a select statement
$sql = "INSERT INTO out_tickets SELECT * FROM tickets";
"DELETE FROM tickets";

if($stmt = mysqli_prepare($link, $sql))
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_id);

// Set parameters
$param_id = trim($_POST["id"]);

// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt))
// Records deleted successfully. Redirect to landing page
header("location: technical.php");
exit();
else
echo "Oops! Something went wrong. Please try again later.";






The information is lacking a bit. Is the code made using PDO? Is the SQL Query is just declared inside a single variable? (Multi query)
– keysl
Aug 12 at 8:43





Also your syntax for delete is wrong. There's no need for *. You could just say. DELETE FROM tickets and everything will be deleted
– keysl
Aug 12 at 8:44





1 Answer
1



As I understand you trying to move ALL columns from one table (t1) to another table (t2) with same structure (or to table, that contain same columns like in first) and than you want to delete data from table1 that you moved to t2?
If correct use next SQL


INSERT INTO t2 SELECT * FROM t1;
DELETE FROM t1 WHERE 1;





Thanks, I am actually trying to move and then delete a specific row from one table1 to table2 then delete that entry from table one. (the id's will be different)
– Allrounder
Aug 12 at 8:55





Is column that you trying to move already exists in table2? In this case you need to execute: DELETE FROM t1 INNER JOIN t2 ON t1.id = t2.id (or your clause) WHERE t2.column = (your clause); Sorry, is my explanation is clear?
– Igor Skobelev
Aug 12 at 9:03






No it does not exist, basically i just need to move the data from table1 to table2 then delete the selected data from table1
– Allrounder
Aug 12 at 9:08





In that case you firstly need to create column(s) at table2:
– Igor Skobelev
Aug 12 at 9:15





Sorry, misunderstood you there. I have a second table with exact same rows as table1
– Allrounder
Aug 12 at 9:17






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard