MySQL/scripts

From Christoph's Personal Wiki
Revision as of 23:35, 23 July 2007 by Christoph (Talk | contribs)

Jump to: navigation, search
  • Find duplicate entries
SELECT accession,count(*) AS n
FROM mydb
WHERE kingdom!='Bacteria'
GROUP BY accession HAVING n>2;
  • Padding integers

Say you have a series of integers for your id column in a table and you wish to pad them with zeros if they are less than 1000 (i.e., "1" -> "001"), then:

SELECT RIGHT(1000 + id,3) AS id FROM mydb;