sql-delete

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

前提是你 提交于 2019-12-17 08:55:01
问题 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] 回答1: 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.

How do I delete all the duplicate records in a MySQL table without temp tables

别说谁变了你拦得住时间么 提交于 2019-12-17 04:27:04
问题 I've seen a number of variations on this but nothing quite matches what I'm trying to accomplish. I have a table, TableA , which contain the answers given by users to configurable questionnaires. The columns are member_id, quiz_num, question_num, answer_num . Somehow a few members got their answers submitted twice. So I need to remove the duplicated records, but make sure that one row is left behind. There is no primary column so there could be two or three rows all with the exact same data.

MySQL DELETE FROM with subquery as condition

北慕城南 提交于 2019-12-17 02:58:53
问题 I am trying to do a query like this: DELETE FROM term_hierarchy AS th WHERE th.parent = 1015 AND th.tid IN ( SELECT DISTINCT(th1.tid) FROM term_hierarchy AS th1 INNER JOIN term_hierarchy AS th2 ON (th1.tid = th2.tid AND th2.parent != 1015) WHERE th1.parent = 1015 ); As you can probably tell, I want to delete the parent relation to 1015 if the same tid has other parents. However, that yields me a syntax error: You have an error in your SQL syntax; check the manual that corresponds to your

How to Delete using INNER JOIN with SQL Server?

怎甘沉沦 提交于 2019-12-16 20:05:35
问题 I want to delete using INNER JOIN in SQL Server 2008 . But I get this error: Msg 156, Level 15, State 1, Line 15 Incorrect syntax near the keyword 'INNER'. My code: DELETE FROM WorkRecord2 INNER JOIN Employee ON EmployeeRun=EmployeeNo WHERE Company = '1' AND Date = '2013-05-06' 回答1: You need to specify what table you are deleting from, here is a version with an alias: DELETE w FROM WorkRecord2 w INNER JOIN Employee e ON EmployeeRun=EmployeeNo WHERE Company = '1' AND Date = '2013-05-06' 回答2:

How to delete Multiple row from one table in sqlite iOS?

北战南征 提交于 2019-12-13 22:14:50
问题 I have a table, MessageTable in sqlite.I want to delete selected rows from it. How can I achieve that. I have searched hard but didn't get any suitable answer. Any help would be appreciated. TIA. 回答1: If you want to delete the multiple selected rows from a table, IN clause will be the one of the best choice. While deleting the rows you need to take care what kind of column you are going to mention in the condition. Here are the various data types mentioned how to delete the set of rows from a

Delete rows matching substring with LIKE?

我是研究僧i 提交于 2019-12-13 16:34:57
问题 How do you delete rows from a table, where a column contains a substring, but the type of that column is 'Long'. (Yes, I know I shouldn't use Long, but I'm maintaining someone else's mess). My first attempt was: delete from longtable where search_long(rowid) like '%hello%'; (Following on from this answer.) This returns: SQL Error: ORA-04091: table blah.longtable is mutating, trigger/function may not see it 回答1: I just replicated your problem and got the same error - it seems the function can

Delete an SQL query result set

帅比萌擦擦* 提交于 2019-12-13 11:06:09
问题 I'm trying to delete an SQL result set but it won't work: DELETE FROM votes WHERE id IN ( SELECT * FROM votes v LEFT JOIN comments c ON f.id = v.post_id GROUP BY v.id HAVING COUNT(c.comment) = 0 ) 回答1: It's true, that you can't use the same table from which you want to delete rows in a direct subselect, but with a little trick - a subselect on a subselect as derived table - you can do it: DELETE FROM votes WHERE id IN ( SELECT t.id FROM ( SELECT v.id, COUNT(c.comment) cnt FROM votes v LEFT

In MySQL how do I use a user defined variable in a WHERE IN clause?

房东的猫 提交于 2019-12-13 08:53:17
问题 I don't understand why this does not work. Can someone explain what I need to do? SET @my_list = '2,6,8,10,12,13,14,18,19,21'; DELETE FROM my_table WHERE my_table.table_id IN (@my_list); 回答1: It's interpreting @my_list as a single id and so you're asking it to delete from my_table where your id is the string "2,6,8,10,12,13,14,18,19,21" You could try SET @my_list = '2,6,8,10,12,13,14,18,19,21'; SET @exec = CONCAT('DELETE FROM my_table WHERE my_table.table_id IN (', @my_list ,')'); EXECUTE (

How to Delete MSSQL Table Datetime GETDATE() Columns if they are One Year Old or Older Using PHP

感情迁移 提交于 2019-12-13 04:41:39
问题 My column is named order_date and the data for it is: datetime NOT NULL DEFAULT GETDATE(), This will make data appear as: Apr 8 2014 3:24PM I am wondering what PHP Query I can use to delete any rows in this MSSQL table if they are one year old or older. I would also like a way to test if this works. (IE: Modifying a current row's order_date column to make it a year older.) If anyone can help me with this it is greatly appreciated. T 回答1: delete from tracking_orders where DATEDIFF (year, order

JMeter: How to benchmark data deletion from database table in batches?

我怕爱的太早我们不能终老 提交于 2019-12-13 04:05:12
问题 I am trying to compare the performance difference between DELETE batch sizes using JMeter. I have a table which I populate with a large amount of test data. Next, I have a JDBC Request that runs the following statement: delete from tbl where (entry_dt < '2019-02-01') and (rownum <= 10000); I want to keep running this until the table is empty, and record the time taken to clear the table. I will run this thread multiple times to get an average execution time, and repeat this process for