sql-delete

Delete recursive children

徘徊边缘 提交于 2019-12-10 20:10:42
问题 I have the following sql that gets me all the children and grandchildren of a root forumpost. with recursive all_posts (id, parentid, root_id) as ( select t1.id, t1.parent_forum_post_id as parentid, t1.id as root_id from forumposts t1 union all select c1.id, c1.parent_forum_post_id as parentid, p.root_id from forumposts c1 join all_posts p on p.id = c1.parent_forum_post_id ) select fp.id from forumposts fp inner join all_posts ap on fp.id=ap.id where root_id=1349 group by fp.id Thing is I

MySQL delete all results of sub-query

和自甴很熟 提交于 2019-12-10 17:19:44
问题 Okay, so if you would like a back story, look at my previous question Figuring out which of my records is not a duplicate is quite easy: SELECT * FROM eventlog GROUP BY event_date, user HAVING COUNT(*) = 1 ORDER BY event_date, user This returns all of my non-duplicates. So I thought I'd move them over to another table called "no_duplicates" and then delete them from the original table. Then I could see the duplicates all alone in the original table, fix them up, and add the no_dupes back. But

How long should a Primary Key delete take?

99封情书 提交于 2019-12-10 15:15:58
问题 Picture a simple table structure: Table1 Table2 ---------- ---------- ID<-------| ID Name |-->Table1ID Name Table1 has a few million rows (say 3.5 million for example). I issue a delete by Primary Key: DELETE FROM Table1 WHERE ID = 100; There is no row in Table2 that references Table1 with ID = 100 , so the delete works without violating any Foreign Key constraints. How long would you expect the delete to take? On the order of a few milliseconds? A few hundred milliseconds? A second or more?

delete from 3 tables with one query

感情迁移 提交于 2019-12-10 15:14:40
问题 i have 3 tables and i dont want define any foreign key in my tables. my tables structure are like below: tables diagram i have written this query : delete relativedata, crawls, stored from relativedata inner join crawls on relativedata.crawl_id = crawls.id and relativedata.id = ? inner join stored on stored.crawl_id = crawls.id this query works for me unless one of tables has no records. now how can i do this delete in 3 tables in 1 query? 回答1: If it works if all tables have records, try

Trying to delete when not exists is not working. Multiple columns in primary key

巧了我就是萌 提交于 2019-12-10 15:09:32
问题 I am currently trying to delete from Table A where a corresponding record is not being used in Table B. Table A has Section, SubSection, Code, Text as fields, where the first three are the Primary Key. Table B has ID, Section, SubSection, Code as fields, where all four are the Primary Key. There are more columns, but they are irrelevant to this question...just wanted to point that out before I get questioned on why all columns are part of the Primary Key for Table B. Pretty much Table A is a

How to remove rest of the rows with the same ID starting from the first duplicate?

故事扮演 提交于 2019-12-10 14:53:26
问题 I have the following structure for the table DataTable : every column is of the datatype int, RowID is an identity column and the primary key. LinkID is a foreign key and links to rows of an other table. RowID LinkID Order Data DataSpecifier 1 120 1 1 1 2 120 2 1 3 3 120 3 1 10 4 120 4 1 13 5 120 5 1 10 6 120 6 1 13 7 371 1 6 2 8 371 2 3 5 9 371 3 8 1 10 371 4 10 1 11 371 5 7 2 12 371 6 3 3 13 371 7 7 2 14 371 8 17 4 ................................. ................................. I'm

Delete user completely [closed]

谁说胖子不能爱 提交于 2019-12-10 12:16:46
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . If a user or an admin wanted to delete a user completely from the site. how would you go about setting a query to remove that user from every table/subtables where the users id is contained. Here is the list of my tables with the subtables where the possible id of an individual

MySQL attempting to delete all rows which are not constrained by foreign key

二次信任 提交于 2019-12-10 09:31:51
问题 Okay, this is (probably) a very simple question, but I am afraid I know almost no MySQL, so please put up with me. I'm just trying to delete every row from one table which is not constrained by a Foreign Key in another table - a specific table, there are only two tables involved here. The create statements look a bit like: CREATE TABLE `testschema`.`job` ( `Job_Id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Comment` varchar(255) DEFAULT NULL, PRIMARY KEY (`Job_Id`) USING BTREE, ) ENGINE

SQLite, check if TEXT field has any alphabetical chars in it

假装没事ソ 提交于 2019-12-10 04:24:40
问题 Okay, so I have a huge list of entries, and in one of the columns (for simplicity let's call it num there's a number, something like 123456780000 (they are all the same length and format), but sometimes there are fields that look something like this 12345678E000 or 12345678H000 Now, I need to delete all the rows in which the num column is not entirely numeric. The type of num is TEXT , not INTEGER . So the above examples should be deleted, while 123456780000 should not. I have tried two

MySQL delete with nested select query

≡放荡痞女 提交于 2019-12-10 02:26:46
问题 I have the following MySQL query: DELETE FROM catalogue WHERE catalogue_id IN ( SELECT catalogue_id FROM catalogue WHERE ( product_id = (SELECT product_id FROM catalogue WHERE catalogue_id = '2290') AND length_id = (SELECT length_id FROM catalogue WHERE catalogue_id = '2290') AND gauge_id = (SELECT gauge_id FROM catalogue WHERE catalogue_id = '2290') ) ) But when I attempt to execute I get the following error message: You can't specify target table 'catalogue' for update in FROM clause Could