sql-delete

How to break ties when comparing columns in SQL

情到浓时终转凉″ 提交于 2020-08-10 23:57:53
问题 I am trying to delete duplicates in Postgres. I am using this as the base of my query: DELETE FROM case_file as p WHERE EXISTS ( SELECT FROM case_file as p1 WHERE p1.serial_no = p.serial_no AND p1.cfh_status_dt < p.cfh_status_dt ); It works well, except that when the dates cfh_status_dt are equal then neither of the records are removed. For rows that have the same serial_no and the date is the same, I would like to keep the one that has a registration_no (if any do, this column also has NULLS

How to break ties when comparing columns in SQL

非 Y 不嫁゛ 提交于 2020-08-10 23:56:13
问题 I am trying to delete duplicates in Postgres. I am using this as the base of my query: DELETE FROM case_file as p WHERE EXISTS ( SELECT FROM case_file as p1 WHERE p1.serial_no = p.serial_no AND p1.cfh_status_dt < p.cfh_status_dt ); It works well, except that when the dates cfh_status_dt are equal then neither of the records are removed. For rows that have the same serial_no and the date is the same, I would like to keep the one that has a registration_no (if any do, this column also has NULLS

PHP Form to delete records in mySQLi when displaying then in a table

你离开我真会死。 提交于 2020-06-23 16:48:51
问题 I'm making a system to display pages in the system in a table and one of the columns is the action column giving people the option to delete the page. I did this: listpages.php <?php $sql = "SELECT * FROM Pages"; $result = $conn->query($sql); if ($result) { while($row = $result->fetch_assoc()) { $pages[] = array_map('htmlspecialchars', $row); } } // PHP is finished now, here's the HTML ?> <form method="post" action="utils/delpage.php"> <table> <thead> <tr> <th>Page Name</th> <th>Page Type</th

Slow self-join delete query

笑着哭i 提交于 2020-02-25 09:42:11
问题 Does it get any simpler than this query? delete a.* from matches a inner join matches b ON (a.uid = b.matcheduid) Yes, apparently it does... because the performance on the above query is really bad when the matches table is very large. matches is about 220 million records. I am hoping that this DELETE query takes the size down to about 15,000 records. How can I improve the performance of the query? I have indexes on both columns. UID and MatchedUID are the only two columns in this InnoDB

Slow self-join delete query

六眼飞鱼酱① 提交于 2020-02-25 09:42:03
问题 Does it get any simpler than this query? delete a.* from matches a inner join matches b ON (a.uid = b.matcheduid) Yes, apparently it does... because the performance on the above query is really bad when the matches table is very large. matches is about 220 million records. I am hoping that this DELETE query takes the size down to about 15,000 records. How can I improve the performance of the query? I have indexes on both columns. UID and MatchedUID are the only two columns in this InnoDB

Slow self-join delete query

梦想的初衷 提交于 2020-02-25 09:41:57
问题 Does it get any simpler than this query? delete a.* from matches a inner join matches b ON (a.uid = b.matcheduid) Yes, apparently it does... because the performance on the above query is really bad when the matches table is very large. matches is about 220 million records. I am hoping that this DELETE query takes the size down to about 15,000 records. How can I improve the performance of the query? I have indexes on both columns. UID and MatchedUID are the only two columns in this InnoDB