Mysql delete all rows and reset autoincrement

30
Oct
0

delete all the rows of a mysql talble

 

delete from tablename

 

reset the auto increment key

 

ALTER TABLE tablename AUTO_INCREMENT=0

Filed under: mysql

Merging Two Tables in Mysql

27
Oct
0

Ok, I had two mailing lists I needed to add together (minus duplicates of coarse)

 

first make sure both talbes have the same fields (one had “last_name” and “first_name” fields while the other had just “name”)

 

UPDATE coo_mailing_list SET name = CONCAT(first_name, ‘ ‘, last_name);

 

bam!!! coo_mailing_list has a name field with first and last names in it.

Next merge the two tables into a new table

CREATE TABLE new_mailing_list SELECT DISTINCT * FROM (SELECT name, email FROM mailing_list UNION ALL SELECT name,email FROM coo_mailing_list) sq;

 

add a primary key field and set to auto increment and rename the old and mailing lists  tables and your

your done!

Filed under: mysql

mysql delete rows with duplicate data

8
Jul
0

DELETE
FROM table1
USING table1, table1 AS vtable
WHERE vtable.id > table1.id
AND table1.field_name = vtable.field_name