sql-delete

T-SQL Delete Inserted Records

↘锁芯ラ 提交于 2020-02-01 04:18:35
问题 I know the title may seem strange but this is what I want to do: I have table with many records. I want to get some of this records and insert them in other table. Something like this: INSERT INTO TableNew SELECT * FROM TableOld WHERE ... The tricky part is that I want this rows that I have inserted to be deleted form the origin table as well. Is there a easy way to do this, because the only think that I have managed to do is to use a temporary table for saving the selected records and then

T-SQL Delete Inserted Records

与世无争的帅哥 提交于 2020-02-01 04:17:25
问题 I know the title may seem strange but this is what I want to do: I have table with many records. I want to get some of this records and insert them in other table. Something like this: INSERT INTO TableNew SELECT * FROM TableOld WHERE ... The tricky part is that I want this rows that I have inserted to be deleted form the origin table as well. Is there a easy way to do this, because the only think that I have managed to do is to use a temporary table for saving the selected records and then

Is there any better way to write this query

我是研究僧i 提交于 2020-01-17 05:37:31
问题 I designed below query for my delete operation. I am new to SQL and just wanted to check with experienced people here if it is fine or any better way to do this. I am using DB2 database DELETE FROM TableD WHERE B_id IN ( SELECT B.B_id FROM TableB tB INNER JOIN TableA tA ON tB.A_id = tA.A_id WHERE A_id = 123 ) AND C_id IN (1,2,3) This has two IN clause which I am little worried and not sure if I could use EXISTS clause anywhere. Database Structure as below: Table A has ONE TO MANY relation

Is there any better way to write this query

…衆ロ難τιáo~ 提交于 2020-01-17 05:37:13
问题 I designed below query for my delete operation. I am new to SQL and just wanted to check with experienced people here if it is fine or any better way to do this. I am using DB2 database DELETE FROM TableD WHERE B_id IN ( SELECT B.B_id FROM TableB tB INNER JOIN TableA tA ON tB.A_id = tA.A_id WHERE A_id = 123 ) AND C_id IN (1,2,3) This has two IN clause which I am little worried and not sure if I could use EXISTS clause anywhere. Database Structure as below: Table A has ONE TO MANY relation

ORA-00933: SQL command not properly ended when deleting two tables at the same time

蹲街弑〆低调 提交于 2020-01-16 07:12:19
问题 I am trying to delete data from two related tables - primary key in the table users and foreign key in the table login - but I'm getting error PL/SQL: ORA-00933: SQL command not properly ended . Create table users and primary key: /* table user*/ create table users (id_user number(10) not null, name_user varchar(30) not null); /* primary key */ alter table users add constraint user_pk primary key (id_user); Create table login and primary key and foreign key: /* table login*/ create table

Mysql query to Delete records after select..? [duplicate]

北城以北 提交于 2020-01-15 20:13:52
问题 This question already has answers here : MySQL Error 1093 - Can't specify target table for update in FROM clause (15 answers) Closed 2 years ago . after selecting records i want to delete that records..i tried following query - (after removing ,MAX(value) but its showing- You can't specify target table 'test' for update in FROM clause DELETE FROM test WHERE ext_no IN ( SELECT ext_no, MAX(value) FROM test GROUP BY ext_no HAVING COUNT(*) > 2 AND COUNT(*) = COUNT(CASE value WHEN 0 THEN 1 END) );

Mysql query to Delete records after select..? [duplicate]

烂漫一生 提交于 2020-01-15 20:11:51
问题 This question already has answers here : MySQL Error 1093 - Can't specify target table for update in FROM clause (15 answers) Closed 2 years ago . after selecting records i want to delete that records..i tried following query - (after removing ,MAX(value) but its showing- You can't specify target table 'test' for update in FROM clause DELETE FROM test WHERE ext_no IN ( SELECT ext_no, MAX(value) FROM test GROUP BY ext_no HAVING COUNT(*) > 2 AND COUNT(*) = COUNT(CASE value WHEN 0 THEN 1 END) );

Mysql query to Delete records after select..? [duplicate]

烂漫一生 提交于 2020-01-15 20:11:19
问题 This question already has answers here : MySQL Error 1093 - Can't specify target table for update in FROM clause (15 answers) Closed 2 years ago . after selecting records i want to delete that records..i tried following query - (after removing ,MAX(value) but its showing- You can't specify target table 'test' for update in FROM clause DELETE FROM test WHERE ext_no IN ( SELECT ext_no, MAX(value) FROM test GROUP BY ext_no HAVING COUNT(*) > 2 AND COUNT(*) = COUNT(CASE value WHEN 0 THEN 1 END) );

Delete records after 15 minutes

倾然丶 夕夏残阳落幕 提交于 2020-01-15 05:51:53
问题 I've got an inactive system. It is supposed to delete users from inactive table after 15 minutes. I have also a code that logs the user out if it cant be found in that table. The inactive script updates user on every page refresh. This is the inactive code I tried and it doesn't work so far: $result = mysqli_query($con,"SELECT * FROM inactive"); while($row = mysqli_fetch_array($result)) if ($row['inactive'] > timestampadd(MINUTE, -15, now())) { }else { $db_query = "DELETE FROM inactive WHERE