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
9
votes
7 answers

Removing duplicate rows from a table in DB2 in a single query

I have a table with 3 columns as below: one | two | three | name ------------------------------------ A1 B1 C1 xyz A1 B1 C1 pqr -> should be deleted A1 B1 C1 lmn …
Vicky
  • 16,679
  • 54
  • 139
  • 232
8
votes
6 answers

SQL DELETE - Maximum number of rows

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…
Rumpleteaser
  • 4,142
  • 6
  • 39
  • 52
8
votes
2 answers

Deleting multiple records in a table using join in Peewee?

Since joining is not allowed on "delete" queries in Peewee, what is the best way to delete all records in table_2 that match a specific condition in related table_1? Using a simple example, I want to achieve the equivalent of this: DELETE…
David
  • 110
  • 1
  • 7
8
votes
2 answers

Does TRUNCATE TABLE grows up transaction log?

I have read that one of the differences between DELETE and TRUNCATE TABLE in Sql is the TRUNCATE operation cannot be rolled back and no triggers will be fired (as written in this site for example) : QUESTION: Does this mean that when I TRUNcATE…
pencilCake
  • 51,323
  • 85
  • 226
  • 363
8
votes
1 answer

Can't truncate MySQL table, while being able to delete all the records

I'm a very beginner to relations, so this may sound dumb. But, what is the difference (in MySQL) between truncating a table and removing all the records (this answer says only about performance)? I was playing (in phpMyAdmin) with one of my test…
trejder
  • 17,148
  • 27
  • 124
  • 216
8
votes
7 answers

Delete large amount of data in sql server

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…
masoud ramezani
  • 22,228
  • 29
  • 98
  • 151
8
votes
2 answers

SQL - return deleted rows

I would like to combine a SELECT which returns rows and a DELETE which deletes a subset of the rows I selected? Is this possible?
Geoff Scott
  • 897
  • 1
  • 10
  • 17
8
votes
2 answers

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

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…
Neel
  • 537
  • 3
  • 8
  • 19
8
votes
2 answers

How to optimize DELETE .. NOT IN .. SUBQUERY in Firebird

I've this kind of delete query: DELETE FROM SLAVE_TABLE WHERE ITEM_ID NOT IN (SELECT ITEM_ID FROM MASTER_TABLE) Are there any way to optimize this?
Harriv
  • 6,029
  • 6
  • 44
  • 76
8
votes
4 answers

Codeigniter deleting data with joins tables

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…
Jatin Dhoot
  • 4,294
  • 9
  • 39
  • 59
7
votes
4 answers

How to delete all records created today?

I am dealing with a very big database ~ 6 Million records. I've added ~30,000 bad records today. How can I delete all of the records created today in MySQL?
JZ.
  • 21,147
  • 32
  • 115
  • 192
7
votes
1 answer

Multiple expressions with IN

I have two somewhat big (4+ million records) tables with identical structure, and they have about 300k duplicated rows. I'd like to DELETE the duplicate rows using the DELETE IN syntax. I've already done it using the MERGE statement (available only…
ivanmp
  • 519
  • 1
  • 5
  • 13
7
votes
3 answers

How can I delete expired data from a huge table without having the log file grow out of control?

I have a huge table (3 billion rows), which unfortunately contains mostly expired data. I want to simply delete all of these expired rows, and keep the rest. I can execute a statement like this: delete from giganticTable where exp_date <…
polygenelubricants
  • 376,812
  • 128
  • 561
  • 623
7
votes
3 answers

Android room database delete is not working?

I made some simple project for test, but i'm having some trouble with delete. It won't work. I can add contact normally, but when I try to delete it, nothing happens and i don't have any erros. Here is my code: Entity @Entity public class Contact…
mark_donys
  • 71
  • 1
  • 2
7
votes
2 answers

Delete multiple records by list of id's with HQL statement

I want to delete multiple records of a certain entity where the id of the entity is in the list of ids I have. I am trying to perform this action in C# with NHibernate. What I have is a list of Ids. I want to do something similar to this : var…
Jan
  • 9,858
  • 7
  • 26
  • 33