sql-delete

List of emails, delete rows out of a table

我的未来我决定 提交于 2019-12-24 08:07:50
问题 If I have a list of of email accounts in a .txt file, is there a way I can perform a mysql delete statement for each instance of the rows that contain the email account against a table? We have a newsletter mailing list which around 600 emails are currently invalid, and we want an easier way of getting rid of them besides manually going in one by one to do it. 回答1: Assuming you want to use the text file's contents as the source of addresses to delete from the database: $addreses = file(

How do I delete one of my two duplicate rows of data in Postgres?

旧时模样 提交于 2019-12-24 07:59:29
问题 I’m using Postgres 9.5. I have the below query that is designed to find identical rows of data (but unique IDs) in my table. select e.name, e.day, e.distance, e.created_at, e2.created_at from events e, events e2 where e.name = e2.name and e.distance = e2.distance and e.day = e2.day and e.web_crawler_id = e2.web_crawler_id and e.id <> e2.id and e.web_crawler_id = 1 order by e.day desc; I ultimately want to delete one of the duplicate rows — so perhaps deleting the row with the greatest

Conditional CASCADE operation for foreign key constraint?

好久不见. 提交于 2019-12-24 01:54:43
问题 I have parent and child table where child has a FK pointing to the PK of parent table. When I delete something in parent table I can have child records deleted as well by having ON DELETE CASCADE . However, in my parent table I don't delete records at all. Instead I set the column state = "passive" . I want to delete related entries in the child table. Do we have something like a "conditional CASCADE" in Postgres? Or is the solution to manually delete entries in the child table? 回答1: You

What is the syntax for a multi-table delete on a MySQL database using Doctrine?

半城伤御伤魂 提交于 2019-12-24 01:27:12
问题 Using Doctrine, I am trying to delete records in a single table based on data gathered from multiple tables. 'companies_groups' is an association table linking 'companies' to 'groups'. I want to delete all records in this table linked to a specific company, with the restriction that only 'companies_groups' records linked to a 'public' group will be deleted. If I were to write this in pure SQL, it would look something like this: DELETE companies_groups FROM companies_groups, groups WHERE

SQLite changes() function reports 0 rows changed in certain delete statements

大城市里の小女人 提交于 2019-12-24 00:23:46
问题 I've recently found the CHANGES() function available inside of SQLite. I'm doing something like the following inside of my Android code: db.execSQL(sqlStatement, argumentArray); int result; SQLiteStatement stmt = db.compileStatement("SELECT CHANGES()"); try { return stmt.simpleQueryForLong(); } finally { stmt.close(); } What I'm seeing that I get good data for all statements such as: UPDATE `footable` SET `stuff` = 'fepojefpjo' (returns 1 row updated) DROP TABLE `footable` (returns 2 rows

Delete all records in table which have no reference in another table

帅比萌擦擦* 提交于 2019-12-23 19:25:18
问题 I have a table which is called Document . Document : id int docuid int doc blob Then I have two referencing tables AppRequiredDocuments : id int appid int docid int -> references document -> id AppDocuments : id int appid int docid int -> references document -> id I have due to an very old migration orphaned items in the document table which have to references in the other tables. How can I delete only the documents in the document table which are not referenced in AppDocuments or

mysql_query(“DELETE FROM table WHERE id-'$id'”); fails [closed]

北城以北 提交于 2019-12-23 15:25:26
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I'm trying to delete a row from my mySQL database via PHP and it isn't working. I have tried the following: mysql_query("DELETE FROM table WHERE id='$id'"); mysql_query("DELETE FROM 'table' WHERE id='$id'"); mysql_query("DELETE FROM `table` WHERE id=`$id`"); $id is the unique identifier and I've echoed it to

SQLAlchemy: How to Delete with join

烂漫一生 提交于 2019-12-23 10:17:49
问题 I have trouble doing such thing bottom with SQLAlchemy: DELETE a FROM a INNER JOIN b ON b.`aId` = a.`Id` WHERE `b`.`xxx` = ?; As the post here: SQLAlchemy: Create delete query using self-join on MySQL I've got it's hard to do delete in SQLAlchemy with join. So I'm now doing like this: session.execute('DELETE a FROM a INNER JOIN b ON b.`aId` = a.`Id` WHERE `b`.`xxx` = %d;'%xxx) But it just annoy me a lot like about: SQL Injection thing, etc.. Is there any way using SQLAlchemy to solve the

Codeigniter deleting data with joins tables

我是研究僧i 提交于 2019-12-23 07:46:32
问题 Logically in SQL we can delete data from tables with JOINS e.g. DELETE clb_subscriber_group_mapping .* FROM clb_subscriber_group_mapping INNER JOIN clb_driver_group ON (clb_driver_group.id = clb_subscriber_group_mapping.driver_group_id) INNER JOIN clb_company ON (clb_company.id = clb_driver_group.company_id) WHERE clb_company.id = 256 AND clb_subscriber_group_mapping.subscriber_id = 1784; What will be the CodeIgniter equivalent of above query? Does CodeIgniter support Delete query with joins?

Trigger to delete rows from related tables before deleting rows from actual table

此生再无相见时 提交于 2019-12-23 03:47:14
问题 I have the following tables: CREATE TABLE QUESTION( id varchar(10) NOT NULL PRIMARY KEY, que_type numeric(1)); CREATE TABLE ESSAY( que_id varchar(10) NOT NULL PRIMARY KEY, ans varchar(2000), FOREIGN KEY (que_id) REFERENCES QUESTION (id)); CREATE TABLE TFFB( que_id varchar(10) NOT NULL PRIMARY KEY, ans varchar(50), FOREIGN KEY (que_id) REFERENCES QUESTION (id)); CREATE TABLE MCQ( que_id varchar(10) NOT NULL PRIMARY KEY, ans varchar(200), FOREIGN KEY (que_id) REFERENCES QUESTION (id)); and try