Sometimes it's just not wise to work on a database after midnight when your senses are not fully alert!
Anyhow, I don't know how I did this but I inserted 7,000+ records for a single content type (restaurants) half of which were duplicate entries.
After realizing that I can't perform a subquery against the same table to delete the duplicates I quickly turned to Temporary Tables (TT). The reason I used a TT was for the simple fact that I was
temporarily using it and I was the
only person who could use it. Additionally, once I was done fixing the issue I didn't want to have to worry about forgetting to drop the TT (keep in mind it is late, I'll forget anything). TT's are only accessible during a single db connection and drops when the connection is dropped reducing chances to pollute the db with garbage.
Some may be wondering, why didn't you just create a new table with a subquery selecting the distinct records to construct and populate a new table and then rename it. The reason being is that the 'records' table contains multiple content types with their own set of data and I didn't want to take any chances on messing them up.
So using a subquery
SELECT DISTINCT tablefields FROM tablename WHERE criteria to select content type records I created a new TT along with the matching records.
CREATE TEMPORARY TABLE restaurants_temp
SELECT DISTINCT title,address,city,zipcode,state FROM records where datatype = 1;
Next, I dropped all of the original records from the 'records' table.
DELETE FROM records where datatype = 1;
Finally, I inserted all of the records from the 'restaurants_temp' table into the 'records' table via use of a subquery.
INSERT INTO records (title,address,city,zipcode,state)
SELECT title,address,city,zipcode,state FROM restaurants_temp;
Close connection and TT is dropped. Don't have to worry about the db being junked up with garbage.
Comments
Thu, 14.08.2008 16:58
Thanks for the tip. I made a slight mod you might be interested [...]
Mon, 28.07.2008 15:06
Solution (to my issue): Views > Tools > Flush Views Cache It explains that Views doesn't always keep up with changes [...]
Mon, 28.07.2008 14:52
Thanks for this helpful post. I've seen this effect too. I'm running into a different (but related?) issue - the Views [...]
Tue, 15.07.2008 20:25
Oscar, Krista from Calais here, writing to let you know that Calais 2.1 is live. In addition to our ongoing [...]
Tue, 01.07.2008 11:30
Dan, You are absolutely correct and I should have stated this within my post; the described steps within the post [...]
Mon, 30.06.2008 09:45
i wouldnt recomand this at all, because if something happens and the conection is lost u will have your data lost if the [...]
Mon, 09.06.2008 13:42
PDT syntax highlighting support does not seem to work when subclipse is installed, any one else had this problem?
Mon, 09.06.2008 11:56
I didn't mean to imply that you were bashing unit tests.
Mon, 09.06.2008 11:52
My point isn't to bash unit tests, but rather to say there are a bunch of things you should be doing before you get [...]
Mon, 09.06.2008 11:43
I agree with, what I think is, the gist of your argument. That is, if you don't write code that anticipates failure, [...]
Mon, 09.06.2008 08:58
clipse is an open source IDE — or as they put it themselves: “universal toolset for development”. It [...]
Tue, 27.05.2008 12:17
Navigation links should fill their container to ensure ease of selection. A good method for that is to make them [...]
Thu, 22.05.2008 10:35
One of the better comments I've seen in a while: "Although I like PHP, I agree the language is only as good as the [...]
Tue, 20.05.2008 14:03
Oscar, Yahoo's Term Extraction service takes an entire article and returns a few of (what it thinks are) the most [...]
Tue, 20.05.2008 13:13
Hi, Tom Tague from Calais here. First, thanks for taking note of Calais. And integrating an example right within the [...]