sql-delete

Mysql delete statement with limit

强颜欢笑 提交于 2019-11-27 09:24:13
I'm trying to delete rows from a table but I get an error. DELETE FROM `chat_messages` ORDER BY `timestamp` DESC LIMIT 20, 50; I get this error at 50: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 50' at line 1 No idea what's wrong. You cannot specify offset in DELETE 's LIMIT clause. So the only way to do that is to rewrite your query to something like: DELETE FROM `chat_messages` WHERE id IN (select id from (select id FROM `chat_messages` ORDER BY `timestamp` DESC LIMIT 20, 50) x) Supposing that you

How to delete/create databases in Neo4j?

大城市里の小女人 提交于 2019-11-27 09:11:57
问题 Is it possible to create/delete different databases in the graph database Neo4j like in MySQL? Or, at least, how to delete all nodes and relationships of an existing graph to get a clean setup for tests, e.g., using shell commands similar to rmrel or rm ? 回答1: You can just remove the entire graph directory with rm -rf , because Neo4j is not storing anything outside that: rm -rf data/* Also, you can of course iterate through all nodes and delete their relationships and the nodes themselves,

MySQL delete row from multiple tables

独自空忆成欢 提交于 2019-11-27 09:09:48
Is this the correct way to do it? DELETE t1, t2, t3, t4 FROM table1 as t1 INNER JOIN table2 as t2 on t1.id = t2.id INNER JOIN table3 as t3 on t1.id=t3.id INNER JOIN table4 as t4 on t1.id=t4.id WHERE t1.username='%s' AND t1.id='%s' Yes, that is correct. It works fine here: CREATE TABLE table1 (id int, username nvarchar(30)); CREATE TABLE table2 (id int); CREATE TABLE table3 (id int); CREATE TABLE table4 (id int); INSERT INTO table1 VALUES (1, 'Foo'),(2, 'Bar'); INSERT INTO table2 VALUES (1),(2); INSERT INTO table3 VALUES (1),(2); INSERT INTO table4 VALUES (1),(2); SELECT COUNT(*) FROM table1; 2

Select item from JCombobox and delete the row in database

有些话、适合烂在心里 提交于 2019-11-27 08:50:46
问题 I am working on a project in which I have a SQLite database with a table called Table1 and values title/location without an ID as column etc... My form has a combobox which I've managed to get it display my DB each entry in one row . Now I want with a button "Delete" to delete the row that I have selected in the combobox and I am kind of lost. Here is my code for the combobox (I think it's fine): private void FillCombo(){ try { String newLine = System.getProperty("line.separator"); Class

JPA delete all entites works strange

余生长醉 提交于 2019-11-27 08:30:44
问题 I have an entityrelation like this: In the ParentObj class: @OneToMany(mappedBy = "parentObj", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) private List<ChildObj> list; In the ChildObj class: @JoinColumn(name="PARENT_OBJ") @ManyToOne private ParentObj parentObj; When the parent object persisted or removed, the child is persisted/removed as well. BUT when I try to remove all the entities with a CriteriaDelete like: CriteriaDelete<ParentObj> query = builder

How to delete the top 1000 rows from a table using Sql Server 2008?

女生的网名这么多〃 提交于 2019-11-27 07:01:54
I have a table in SQL Server. I would like to delete the top 1000 rows from it. However, I tried this, but I instead of just deleting the top 1000 rows it deleted all the rows in the table. Here is the code: delete from [mytab] select top 1000 a1,a2,a3 from [mytab] Martin Smith The code you tried is in fact two statements. A DELETE followed by a SELECT . You don't define TOP as ordered by what. For a specific ordering criteria deleting from a CTE or similar table expression is the most efficient way. ;WITH CTE AS ( SELECT TOP 1000 * FROM [mytab] ORDER BY a1 ) DELETE FROM CTE May be better for

How to efficiently delete rows while NOT using Truncate Table in a 500,000+ rows table

徘徊边缘 提交于 2019-11-27 06:59:31
Let's say we have table Sales with 30 columns and 500,000 rows. I would like to delete 400,000 in the table (those where "toDelete='1'" ). But I have a few constraints : the table is read / written "often" and I would not like a long "delete" to take a long time and lock the table for too long I need to skip the transaction log (like with a TRUNCATE ) but while doing a "DELETE ... WHERE..." (I need to put a condition), but haven't found any way to do this... Any advice would be welcome to transform a DELETE FROM Sales WHERE toDelete='1' to something more partitioned & possibly transaction log

In SQL, is UPDATE always faster than DELETE+INSERT?

ε祈祈猫儿з 提交于 2019-11-27 06:35:41
Say I have a simple table that has the following fields: ID: int, autoincremental (identity), primary key Name: varchar(50), unique, has unique index Tag: int I never use the ID field for lookup, because my application is always based on working with the Name field. I need to change the Tag value from time to time. I'm using the following trivial SQL code: UPDATE Table SET Tag = XX WHERE Name = YY; I wondered if anyone knows whether the above is always faster than: DELETE FROM Table WHERE Name = YY; INSERT INTO Table (Name, Tag) VALUES (YY, XX); Again - I know that in the second example the ID

I want a trigger to DELETE from 2 tables in MySQL

情到浓时终转凉″ 提交于 2019-11-27 05:56:16
问题 I have 3 MySQL tables ( food , apple , and orange ). I want to delete rows from: apple(idapple, iduser, name) orange(idornge, iduser, name) When deleting a row in food(iduser, name) using one trigger? Here is my trigger so far: CREATE TRIGGER `food_before_delete` AFTER DELETE ON `food` FOR EACH ROW DELETE FROM apple, orange WHERE apple.iduser=OLD.iduser and orange.iduser=OLD.iduser But it won't compile. How can make a trigger that deletes from two tables at once? 回答1: Delete from two tables

How do I delete duplicate rows and keep the first row?

浪子不回头ぞ 提交于 2019-11-27 05:45:52
问题 I made a mistake and I have unwanted duplicates. I have a table with 4 key fields. A1 , k1 , k2 , k3 . A1 is auto increment and the primary key. the combination of k1 , k2 and k3 is supposed to be unique and I have to delete the duplicate rows before I create a unique index. Some rows have one duplicate, some have many. SELECT CONCAT(k1, k2, k) AS dup_value FROM myviews GROUP BY dup_value HAVING (COUNT(dup_value) > 1) shows me duplicates values that I need to deal with. But now I don't know