sql-delete

Very slow delete on mysql base with subquery

泪湿孤枕 提交于 2019-11-30 02:56:11
问题 This mysql query is running for around 10 hours and has not finished. Something is horribly wrong. Two tables (text and spam) are here. Spam stores the ids of spam entrys in text that I want to delete. DELETE FROM tname.text WHERE old_id IN (SELECT textid FROM spam); spam has just 2 columns, both are ints. 800K entries has a file size of several Mbs. Both ints are primary keys. text has 3 columns. id (prim key), text, flags. around 1200K entries, and around 2.1 gigabyte size (most spam). The

DELETE FROM HAVING COUNT(*) in MySQL

眉间皱痕 提交于 2019-11-30 02:39:42
问题 Ok so there are couple posts here already on this and fewer still out on the web. I've literally tried every one of them and can not get anything to work. Hopefully someone here can take pity on me :) Here is the data I'm working with. I want to delete all these records. SELECT part_desc, count(*) as rec_num FROM ag_master GROUP BY part_desc HAVING COUNT(*) > 1000; +--------------------------------------+---------+ | part_desc | rec_num | +--------------------------------------+---------+ |

How to write a trigger to abort delete in MYSQL?

夙愿已清 提交于 2019-11-29 23:18:57
I read this article but it seems not work for delete. I got this error when tried to create a trigger: Executing SQL script in server ERROR: Error 1363: There is no NEW row in on DELETE trigger CREATE TRIGGER DeviceCatalog_PreventDeletion BEFORE DELETE on DeviceCatalog FOR EACH ROW BEGIN DECLARE dummy INT; IF old.id = 1 or old.id =2 THEN SELECT * FROM DeviceCatalog WHERE DeviceCatalog.id=NEW.id; END IF; END; SQL script execution finished: statements: 4 succeeded, 1 failed Try something like this - DELIMITER $$ CREATE TRIGGER trigger1 BEFORE DELETE ON table1 FOR EACH ROW BEGIN IF OLD.id = 1

MySQL WHERE: how to write “!=” or “not equals”?

早过忘川 提交于 2019-11-29 22:45:41
I need to do this DELETE FROM konta WHERE taken != '' But != doesn't exist in mysql. Anyone know how to do this? DELETE FROM konta WHERE taken <> ''; The != operator most certainly does exist! It is an alias for the standard <> operator. Perhaps your fields are not actually empty strings, but instead NULL ? To compare to NULL you can use IS NULL or IS NOT NULL or the null safe equals operator <=> . You may be using old version of Mysql but surely you can use DELETE FROM konta WHERE taken <> '' But there are many other options available. You can try the following ones DELETE * from konta WHERE

SQL Delete Records within a specific Range [duplicate]

删除回忆录丶 提交于 2019-11-29 22:10:29
This question already has an answer here: How to delete multiple rows in SQL where id = (x to y) 5 answers This is probably a very simple question for somebody with experience, but I just wanted to know the safest way to delete a couple of hundred records in an SQL table that fall between a specific range. For example I need to delete rows with an ID between 79 & 296: My worry is if I say delete everything with an ID (>79 AND < 296) then it may literally wipe the whole table. if you use Sql Server delete from Table where id between 79 and 296 After your edit : you now clarified that you want :

Deleting value using SQlite while doing an INNER JOIN

核能气质少年 提交于 2019-11-29 14:29:56
I am trying to delete all voters from a voters table where they are not registered as a democrat or republican AND only voted once. I have a database with three tables, congress_members, voters, and votes and have to JOIN votes with voters in order to delete the right data. This code finds the data I want to delete: SELECT voters.* FROM voters JOIN votes ON voters.id = votes.voter_id WHERE party = 'green' OR party = 'na' OR party = 'independent' GROUP BY votes.voter_id HAVING COUNT(*) = 1; But I am unable to delete it because I am getting an error everytime I try to delete with a JOIN

MySQL: how to drop multiple tables using single query?

不打扰是莪最后的温柔 提交于 2019-11-29 12:35:02
问题 I want to drop multiple tables with ease without actually listing the table names in the drop query and the tables to be deleted have prefix say 'wp_' 回答1: I've used a query very similar to Angelin's. In case you have more than a few tables, one has to increase the max length of group_concat . Otherwise the query will barf on the truncated string that group_concat returns. This is my 10 cents: -- Increase memory to avoid truncating string, adjust according to your needs SET group_concat_max

“The total number of locks exceeds the lock table size” Deleting 267 Records

寵の児 提交于 2019-11-29 10:07:45
I'm trying to delete 267 records out of about 40 million. The query looks like: delete from pricedata where pricedate > '20120413' pricedate is a char(8) field. I know about adjusting innodb_buffer_pool_size , but if I can do select from pricedata where pricedate > '20120413' and get 267 records (and that's all there are), no errors, why does it choke on the delete? And if adjusting innodb_buffer_pool_size doesn't work, what should I do? It seems that you don't have an index on pricedate (or MySQL does not use this index for some reason). With REPEATABLE READ (the default transaction isolation

Remove all table rows from SQLite database table

…衆ロ難τιáo~ 提交于 2019-11-29 03:02:21
I want to remove all rows that i entered from my SQLite database table. The table name is tbltask . I tried to drop the table and delete * from table, but those are giving me runtime errors. I want to trigger this event in Button OnClickListner event. Following code is what I tried: String delete = "DELETE FROM "+DATABASE_TABLE; db.rawQuery(delete, null); db.delete(DATABASE_TABLE, null, null); LogCat: 11-15 17:45:04.660: DEBUG/AndroidRuntime(300): Shutting down VM 11-15 17:45:04.660: WARN/dalvikvm(300): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 11-15 17:45:04.710:

MYSQL delete all results having count(*)=1

≯℡__Kan透↙ 提交于 2019-11-28 21:59:10
I have a table taged with two fields sesskey (varchar32 , index) and products (int11), now I have to delete all rows that having group by sesskey count(*) = 1. I'm trying a fews methods but all fails. Example: delete from taged where sesskey in (select sesskey from taged group by sesskey having count(*) = 1) The sesskey field could not be a primary key because its repeated. DELETE si FROM t_session si JOIN ( SELECT sesskey FROM t_session so GROUP BY sesskey HAVING COUNT(*) = 1 ) q ON q.sesskey = si.sesskey You need to have a join here. Using a correlated subquery won't work. See this article