SELECT DISTINCT <insert all columns but the PK here> FROM foo. Create a temp table using that query (the syntax varies by RDBMS but there’s typically a SELECT … INTO or CREATE TABLE AS pattern available), then blow away the old table and pump the data from the temp table back into it.
Related Posts:
- What’s the best way to search for a UPC code in a Database?
- When should I use CROSS APPLY over INNER JOIN?
- Finding duplicate values in a SQL table
- Count(*) vs Count(1) – SQL Server
- Remove duplicate rows in MySQL
- Best way to test if a row exists in a MySQL table
- MySQL INSERT INTO table VALUES.. vs INSERT INTO table SET
- WP Optimization: Removing Orphaned wp_options (especially the autoload ones)
- Debugging WordPress
- This SQL request call all time and overload my server : SELECT meta_value FROM wp_sitemeta WHERE meta_key = ‘wp_installer_network’ AND site_id = 1
- What is the difference between UNION and UNION ALL?
- Selecting COUNT(*) with DISTINCT
- What is a stored procedure?
- ORA-00904: invalid identifier
- The wait operation timed out. ASP
- Insert Data Into Temp Table with Query
- SQL SELECT WHERE field contains words
- Why do we need “Relationships” between tables at all?
- How to delete duplicate rows in SQL Server?
- Using group by on multiple columns
- How to declare a variable in MySQL?
- ORA-01843 not a valid month- Comparing Dates
- How do you trouble shoot a “Data type mismatch in criteria expression” error in MS Access 2010?
- Inserting data into a temporary table
- How to Select Top 100 rows in Oracle?
- CREATE VIEW must be the only statement in the batch
- SQL Server FOR EACH Loop
- How can I select the first day of a month in SQL?
- Warning: Null value is eliminated by an aggregate or other SET operation in Aqua Data Studio
- Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
- Oracle Apex column link from LOV values
- When to use “ON UPDATE CASCADE”
- MySQL combine two columns into one column
- ORA-01861: literal does not match format string
- SQL Server Insert if not exists
- SQL Server: Invalid Column Name
- Insert text with single quotes in PostgreSQL
- SQL Server IF NOT EXISTS Usage?
- String or binary data would be truncated. The statement has been terminated
- How to insert date values into table
- Error converting data type varchar to float
- How to concatenate text from multiple rows into a single text string in SQL Server
- Arithmetic overflow error converting numeric to data type numeric
- how to remove time from datetime
- “You tried to execute a query that does not include the specified aggregate function”
- How to write a SQL DELETE statement with a SELECT statement in the WHERE clause?
- How to round down to nearest integer in MySQL?
- How do I reset a sequence in Oracle?
- MySQL error: key specification without a key length
- SQL: Two select statements in one query
- How to query MongoDB with “like”
- Check if MySQL table exists without using “select from” syntax?
- MySQL equivalent of DECODE function in Oracle
- mysql update column with value from another table
- what is the difference between triggers, assertions and checks (in database)
- Replacing NULL with 0 in a SQL server query
- SQL Server dynamic PIVOT query?
- How to delete from multiple tables in MySQL?
- What does Include() do in LINQ?
- SQL Server “cannot perform an aggregate function on an expression containing an aggregate or a subquery”, but Sybase can
- Get everything after and before certain character in SQL Server
- Cannot create an instance of OLE DB provider Microsoft.Jet.OLEDB.4.0 for linked server null
- ORDER BY items must appear in the select list if SELECT DISTINCT is specified
- ROW_NUMBER() in MySQ
- LEFT function in Oracle
- Foreign key references invalid table
- What are database constraints?
- How do I view the Explain Plan in Oracle Sql developer?
- ORA-01779: cannot modify a column which maps to a non key-preserved table
- SUM OVER PARTITION BY
- SQLite string contains other string query
- Varchar invalid for Sum operator
- SQL: How to properly check if a record exists
- ora-06553 pls-306 wrong number or types of arguments in call to ‘ogc_x’
- SQL query to extract only the “current” wp_posts?
- Sorting search results by taxonomy terms
- SQL select of users by metadata
- How to properly sanitize strings without $wpdb->prepare?
- How to retrieve sticky post in raw sql?
- How to remove in the wordpress database all posts revisions except the last three?
- Backticks (`) Instead of Single Quotes (‘) in an SQL Statement?
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- $wpdb get_var issue
- Performance : Duplicating `add_action`
- posts_where Fails with More than One Custom Field in Query
- Inserting rows into a custom table, when plugin is activated
- WordPress database error: You have an error in your SQL syntax
- Restose content from revisions – sql query
- Why line returns are not reapply after doing esc_sql?
- WooCommerce database query : Get product category image path+name from thumbnail_id [closed]
- WordPress can I manually add columns in users table and display it in the default manage user plugin and registration form? [closed]
- Minimize Performance Issues of MultiSite Large Number of Tables Created
- How to avoid filling up an array each time I run a WP_query?
- Help me SELECT thumbnail from SQL and use
- Why is my insert row only inserting the final row from the loop into the database rather than just inserting one
- Search results sort order failing: set by date only
- SQL query: select duplicate posts – but using duplicate meta [duplicate]
- Creating a “forum” – showing last post or last commented post
- Replace Unwanted Space in Post Content URL
- How to write inner join using posts_clauses?