SQL

Remove duplicates from a table column in database

You have a table with a column with many duplicates and you just want to keep one of each. Make a distinct copy of the table, remove the old table and rename the new one.

CREATE TABLE temp_table as SELECT * FROM duplicate_table WHERE 1 GROUP BY duplicate_column;

DROP TABLE duplicate_table;

RENAME TABLE temp_table TO duplicate_table;

This example sumarize a value when aggregate to duplicates

How to create a function to determine if a value is numeric in MySQL/SQL

This is how you can create a function in MySQL to determine if a selected value is numeric or not.

<?php
CREATE
FUNCTION IsNumeric (sIn varchar(1024)) RETURNS tinyint DETERMINISTIC
RETURN sIn REGEXP '^(-|\\+){0,1}([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+|[0-9]+)$';

UPDATE nodemap SET`nodemap_city` = CONCAT(SUBSTR(`nodemap_city`, 1, 3), ' ', SUBSTR(`nodemap_city`, 4, 2), SUBSTR(`nodemap_city`, 6)) WHERE IsNumeric(SUBSTR(`nodemap_city`, 1, 5)) = 1 LIMIT 1;
?>

Drupal module order

List your sites activated modules.

SELECT `name` , `status` , `weight` FROM `system` WHERE `type` = 'module' AND `status` =1 ORDER BY weight ASC LIMIT 0 , 200

Compare your sites activated modules with an other sites modules list in the same database.

Pages