Questions tagged [sql-delete]

The SQL DELETE statement allows you to delete a single row or multiple rows from a SQL table.

The DELETE statement removes one or more rows from a table. A subset may be defined for deletion using a condition, otherwise all rows are removed. Some DBMSs, like MySQL, allow to delete rows from multiple tables with one DELETE statement (this is sometimes called multi-table DELETE).

Use this tag instead of which is too broad.

Reference

3082 questions
15
votes
3 answers

How to Delete Records NOT IN

Hi I have the following SQL Query which gives me Scheme_Id which exist both in ProjectSchemes and Schemes table. I want to delete all records from Schemes table which have no record to ProjectSchemes table. How can I do so? Please help. I'm using…
Jobert Enamno
  • 4,403
  • 8
  • 41
  • 63
15
votes
6 answers

Delete multiple rows by selecting checkboxes using PHP

I want to delete multiple rows from my MYSQL database table. I have created this file to select various links and delete them using checkboxes. This doesn't seem to delete any row. My data is populated in the table. I guess the problem is with my…
spyder
  • 330
  • 3
  • 6
  • 18
15
votes
2 answers

REPLACE INTO, does it re-use the PRIMARY KEY?

The REPLACE INTO function in MySQL works in such a way that it deletes and inserts the row. In my table, the primary key (id) is auto-incremented, so I was expecting it to delete and then insert a table with id at the tail of the database. However,…
matt
  • 2,857
  • 7
  • 33
  • 58
15
votes
5 answers

MySQL insert on duplicate key; delete?

Is there a way of removing record on duplicate key in MySQL? Say we have a record in the database with the specific primary key and we try to add another one with the same key - ON DUPLICATE KEY UPDATE would simply update the record, but is there an…
Spencer Mark
  • 5,263
  • 9
  • 29
  • 58
14
votes
5 answers

Very slow delete on mysql base with subquery

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…
rohezal
  • 141
  • 1
  • 4
14
votes
2 answers

DELETE all where MySQL foreign key constraint does not fail

I am trying to delete a few records but am getting the following error: Cannot delete or update a parent row: a foreign key constraint fails The thing is, the foreign key constraint is failing for only 1 or 2 of my 100 records I wish to delete. I…
Garfield
  • 1,247
  • 4
  • 15
  • 33
14
votes
4 answers

MySQL Injection - Use SELECT query to UPDATE/DELETE

I've got one easy question: say there is a site with a query like: SELECT id, name, message FROM messages WHERE id = $_GET['q']. Is there any way to get something updated/deleted in the database (MySQL)? Until now I've never seen an injection that…
Simon
  • 5,464
  • 6
  • 49
  • 85
14
votes
4 answers

Remove duplicate fields from a temp table that has no primary key

I need to remove duplicate fields from a temp table where the fields in question are not exactly identical. For example, I have the following data: First Last DOB John Johnson 10.01.02 Steve Stephens 23.03.02 John Johnson 2.02.99 Dave …
nf313743
  • 4,129
  • 8
  • 48
  • 63
13
votes
1 answer

Laravel 5.4 - Deleting specific records from the pivot table

For each visit I may have many products; therefore the pivot table (product_visit) has the fields: id, product_id, visit_id, qtd and amount. To delete a visit and its related records on the pivot table, everything works fine: public function…
Sérgio Nader
  • 187
  • 1
  • 1
  • 12
13
votes
2 answers

Oracle sql merge to insert and delete but not update

Is there a way to use oracle merge to insert and delete but not update? I have a table representing a set of values related to a single row in another table. I could change the set of values by deleting them all and adding back the new set, or by…
drawnonward
  • 53,459
  • 16
  • 107
  • 112
13
votes
2 answers

Delete SQLite Row with where clause with multiple clauses

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…
Gareth Bowen
  • 341
  • 2
  • 3
  • 11
12
votes
4 answers

Is it possible to Disable deletes on a table on MYSQL?

I'm using MySQL 5.0 and I would like to know if there's a way to disable deletes on a table. As in, not make it possible for ANY user to delete anything from the tablets, only update and insert.
Skynight
  • 507
  • 2
  • 7
  • 24
12
votes
2 answers

MySQL delete with nested select query

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…
bland_dan
  • 448
  • 3
  • 8
  • 19
12
votes
2 answers

SSIS - Delete rows

I'm new to SSIS and need help on this one. I found an article which describes how to detect rows which exist and which have changed. The part that I'm missing is how to update rows that changed. I found some articles which say that it's also good…
ilija veselica
  • 9,414
  • 39
  • 93
  • 147
12
votes
3 answers

How to delete a large record from SQL Server?

In a database for a forum I mistakenly set the body to nvarchar(MAX). Well, someone posted the Encyclopedia Britanica, of course. So now there is a forum topic that won't load because of this one post. I have identified the post and ran a delete…
CatDadCode
  • 58,507
  • 61
  • 212
  • 318