I need to UPDATE ON DUPLICATE for this MySQL query so I can perform the needed actions based on whether or not a particular field was found. If it wasn't found, insert it, otherwise update a few of the fields
I have an id auto_increment field as a primary key. I can't seem to get this to hold when UPDATE ON DUPLICATE works on the primary key. And since id is new with each row, of course all data will then be inserted because it's new data.my $data = qq(INSERT INTO temp (url, altavista, yahoo, msn, teoma, g +oogle, alltheweb, Total) values("$url", "$altavista_results", "$yahoo +_results", "$msn_results", "$teoma_results", "$google_results", "$all +theweb_results", "$total") ON DUPLICATE KEY UPDATE altavista = "$alta +vista_results", yahoo = "$yahoo_results", msn = "$msn_results", teoma + = "$teoma_results", google = "$google_results", alltheweb = "$allthe +web_results", total = "$total"); my $sth = $dbh->prepare($data); $sth->execute() or die $dbh->errstr;
The id column is important because, with it, I can track down the last 10 rows entered into the table.
My question is, what do I have to do in order to perform the insert/or update and the last 10 rows in order to work? It was mentioned in the CB that I could use a time column with $time. It sounds like a great idea but not sure how I'd find the last 10 newest entries based on time.
The second question is, how can I bring back the latest 10 rows AND THEN sort them by a particular field "Total"?
This doesn't sort by Total like it should.my $data = qq[SELECT url, altavista, yahoo, msn, teoma, google, all +theweb, Total FROM temp WHERE id > (SELECT MAX(id) FROM temp) - 10 ORDER BY Total DESC];
In reply to UPDATE ON DUPLICATE and sorting by coldfingertips
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |