sql-delete

How to delete in MS Access when using JOIN's?

梦想与她 提交于 2019-11-26 11:01:56
问题 I am attempting to use the DELETE clause in MS Access and have an issue when also using the JOIN clause. I have notice this can be accomplished by using the DISTINCTROW key word. For example, the following SQL statement does not allow for deletion: DELETE Table1.* FROM Table1 INNER JOIN Table2 ON Table1.Name=Table2.Name; However, this statement does: DELETE DISTINCTROW Table1.* FROM Table1 INNER JOIN Table2 ON Table1.Name=Table2.Name; Why does the DELETE work when using the DISTINCTROW key

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

こ雲淡風輕ζ 提交于 2019-11-26 10:35:51
问题 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

I got error “The DELETE statement conflicted with the REFERENCE constraint”

随声附和 提交于 2019-11-26 09:58:15
问题 I tried to truncate a table with foreign keys and got the message: \" Cannot truncate table because it is being referenced by a FOREIGN KEY constraint \". I read a lot of literature about the problem and thought that I found the solution by using delete DELETE FROM table_name DBCC CHECKIDENT (table_name, RESEED, 0) But I still got an error message: \" The DELETE statement conflicted with the REFERENCE constraint \". When I try to delete with Microsoft Management Studio and execute the

How to delete duplicate entries?

时间秒杀一切 提交于 2019-11-26 09:51:05
I have to add a unique constraint to an existing table. This is fine except that the table has millions of rows already, and many of the rows violate the unique constraint I need to add. What is the fastest approach to removing the offending rows? I have an SQL statement which finds the duplicates and deletes them, but it is taking forever to run. Is there another way to solve this problem? Maybe backing up the table, then restoring after the constraint is added? just somebody For example you could: CREATE TABLE tmp ... INSERT INTO tmp SELECT DISTINCT * FROM t; DROP TABLE t; ALTER TABLE tmp

How to delete and update a record in Hive

梦想的初衷 提交于 2019-11-26 08:47:49
问题 I have install Hadoop, Hive, Hive JD BC. which are running fine for me. But I still have a problem. How to delete or update a single record using Hive because delete or update command of MySQL is not working in hive. Thanks hive> delete from student where id=1; Usage: delete [FILE|JAR|ARCHIVE] <value> [<value>]* Query returned non-zero code: 1, cause: null 回答1: You should not think about Hive as a regular RDBMS, Hive is better suited for batch processing over very large sets of immutable data

Deleting rows with MySQL LEFT JOIN

不羁岁月 提交于 2019-11-26 04:35:30
问题 I have two tables, one for job deadlines, one for describe a job. Each job can take a status and some statuses means the jobs\' deadlines must be deleted from the other table. I can easily SELECT the jobs/deadlines that meets my criteria with a LEFT JOIN : SELECT * FROM `deadline` LEFT JOIN `job` ON deadline.job_id = job.job_id WHERE `status` = \'szamlazva\' OR `status` = \'szamlazhato\' OR `status` = \'fizetve\' OR `status` = \'szallitva\' OR `status` = \'storno\' ( status belongs to job

How to delete duplicate entries?

徘徊边缘 提交于 2019-11-26 03:27:29
问题 I have to add a unique constraint to an existing table. This is fine except that the table has millions of rows already, and many of the rows violate the unique constraint I need to add. What is the fastest approach to removing the offending rows? I have an SQL statement which finds the duplicates and deletes them, but it is taking forever to run. Is there another way to solve this problem? Maybe backing up the table, then restoring after the constraint is added? 回答1: For example you could:

How to delete duplicate rows in SQL Server?

北城余情 提交于 2019-11-26 03:13:52
问题 How can I delete duplicate rows where no unique row id exists? My table is col1 col2 col3 col4 col5 col6 col7 john 1 1 1 1 1 1 john 1 1 1 1 1 1 sally 2 2 2 2 2 2 sally 2 2 2 2 2 2 I want to be left with the following after the duplicate removal: john 1 1 1 1 1 1 sally 2 2 2 2 2 2 I\'ve tried a few queries but I think they depend on having a row id as I don\'t get the desired result. For example: DELETE FROM table WHERE col1 IN ( SELECT id FROM table GROUP BY id HAVING (COUNT(col1) > 1) ) 回答1:

How to delete from multiple tables in MySQL?

谁都会走 提交于 2019-11-26 01:25:27
问题 I am trying to delete from a few tables at once. I\'ve done a bit of research, and came up with this DELETE FROM `pets` p, `pets_activities` pa WHERE p.`order` > :order AND p.`pet_id` = :pet_id AND pa.`id` = p.`pet_id` However, I am getting this error Uncaught Database_Exception [ 1064 ]: 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 \'p, pets_activities pa... I\'ve never done a cross table delete before,

MySQL Error 1093 - Can&#39;t specify target table for update in FROM clause

痴心易碎 提交于 2019-11-26 01:17:25
问题 I have a table story_category in my database with corrupt entries. The next query returns the corrupt entries: SELECT * FROM story_category WHERE category_id NOT IN ( SELECT DISTINCT category.id FROM category INNER JOIN story_category ON category_id=category.id); I tried to delete them executing: DELETE FROM story_category WHERE category_id NOT IN ( SELECT DISTINCT category.id FROM category INNER JOIN story_category ON category_id=category.id); But I get the next error: #1093 - You can\'t