sql-delete

How do I merge two tables in MySQL and where table 1 is primary

懵懂的女人 提交于 2019-12-23 03:12:40
问题 How do I merge two tables in MySQL? I've looked at several other posts on this topic but they don't go into enough detail for me. I'm a novice MySQL user, so bear with me I have a primary table and a temp table that look like this: CREATE TABLE temp_import ( id int(11) NOT NULL auto_increment, Name varchar(255) default NULL, MerchantID int(11) default NULL, SKU varchar(255) default NULL, PRIMARY KEY ( id ) ) ENGINE=MyISAM AUTO_INCREMENT=765811 DEFAULT CHARSET=utf8; I'm inserting data into the

CTE delete not committed until following statements complete

十年热恋 提交于 2019-12-22 16:57:48
问题 The problem I'm having is that deleted data still appears later in the same query. Naturally, in a completely separate query, the deleted data does not appear. This isn't my use-case, but I think this it's the simplest way to show the problem: CREATE TABLE company (id INT PRIMARY KEY, name TEXT); CREATE TABLE employee (id INT PRIMARY KEY, company_id INT REFERENCES company(id), name TEXT); INSERT INTO company VALUES (1, 'first company'); INSERT INTO company VALUES (2, 'second company'); INSERT

The DELETE statement conflicted with the REFERENCE

陌路散爱 提交于 2019-12-22 08:17:44
问题 I have a table_Project with a CustomerID in it (linked to tbl_Customer). In tbl_Customer I have Customer_ID(as key) and some other info like Phone, Email etc. To delete it from the Gridview I use this DeleteCommand: DeleteCommand="DELETE FROM [tbl_Customer] WHERE [Customer_ID] = @Customer_ID" But it gives me the following error: The DELETE statement conflicted with the REFERENCE constraint "Klant_Relatie". The conflict occurred in database "Database_1", table "dbo.tbl_Project", column

DELETE WITH INTERSECT

て烟熏妆下的殇ゞ 提交于 2019-12-22 05:22:10
问题 I have two tables with the same number of columns with no primary keys (I know, this is not my fault). Now I need to delete all rows from table A that exists in table B (they are equal, each one with 30 columns). The most immediate way I thought is to do a INNER JOIN and solve my problem. But, write conditions for all columns (worrying about NULL ) is not elegant (maybe cause my tables are not elegant either). I want to use INTERSECT . I am not knowing how to do it? This is my first question:

How to view/edit/delete records from a checklist table in php/mysql

一曲冷凌霜 提交于 2019-12-22 00:32:49
问题 I've built a checklist table in php, the data gets saved in a mysql database table. With the below code, the data gets saved in the database, now I want to be able to edit and delete the records. The database table has two columns - auto-increment Id and ColRow which has the values of the checked boxes. The values are fetched from the different tables of the database. The header and the first columns are fetched from two tables which gets saved in the report table depending on the boxes being

Delete rows with Laravel query builder and LEFT JOIN

六眼飞鱼酱① 提交于 2019-12-21 20:54:16
问题 How to delete rows from multiple tables in one query (with left join). The query: DELETE `deadline`, `job` FROM `deadline` LEFT JOIN `job` .... So, I try it like this: DB::table('deadline', 'job') ->leftJoin('job', 'deadline.id', '=', 'job.deadline_id') ->where('deadline.id', $id) ->delete(); Seems that Laravel doesn't support delete from multiple tables with left join. Is there a supported way or workaround? 回答1: It seems that my way is not possible. So, I did it like this. $q = 'DELETE

delete duplicate rows and need to keep one from all of them in mysql [duplicate]

半腔热情 提交于 2019-12-21 13:01:22
问题 This question already has answers here : Remove duplicate rows in MySQL (24 answers) Closed 6 years ago . I want to delete duplicate rows based on two columns but need to keep 1 row all of them. Duplicate rows can be more than two rows like, ID NAME PHONE -- ---- ---- 1 NIL 1234 2 NIL 1234 3 NIL 1234 4 MES 5989 I want to delete any of 2 rows from above 3 and keep 1 row. 回答1: DELETE a FROM tableA a LEFT JOIN ( SELECT MIN(ID) ID, Name, Phone FROM TableA GROUP BY Name, Phone ) b ON a.ID = b.ID

SQL DELETE - Maximum number of rows

别说谁变了你拦得住时间么 提交于 2019-12-21 11:22:48
问题 What limit should be placed on the number of rows to delete in a SQL statement? We need to delete from 1 to several hundred thousand rows and need to apply some sort of best practise limit in order to not absolutely kill the SQL server or fill up the logs every time we empty a waste-basket. This question is not specific to any type of database. 回答1: That's a very very broad question that basically boils down to "it depends". The factors that influence it include: What is your level of

Delete SQLite Row with where clause with multiple clauses

泄露秘密 提交于 2019-12-21 08:01:24
问题 I've been searching around and not managed to find a solution or working example so here goes. I've set up an SQLite database which has five columns with different fields which effectively builds a list for the user. There will be multiple values in the list that are the same, save for the ROWID which is set to auto increment. Neither the user nor the program will know the ROWID once a value has been entered into the database, so I want for the user to be able to remove one row if it contains

Delete large amount of data in sql server

房东的猫 提交于 2019-12-21 04:34:13
问题 Suppose that I have a table with 10000000 record. What is difference between this two solution? delete data like : DELETE FROM MyTable delete all of data with a application row by row : DELETE FROM MyTable WHERE ID = @SelectedID Is the first solution has best performance? what is the impact on log and performance? 回答1: If you have that many records in your table and you want to delete them all, you should consider truncate <table> instead of delete from <table> . It will be much faster, but