delete rows from multiple tables

Well, if you had used InnoDB tables, you could set up a cascading delete with foreign keys that would do it all automatically. But if you have some reason for using MyISAM, You just use a multiple-table DELETE: DELETE FROM boards, topics, messages USING boards INNER JOIN topics INNER JOIN messages WHERE boards.boardid = $boardid … Read more

I got error “The DELETE statement conflicted with the REFERENCE constraint”

The error means that you have data in other tables that references the data you are trying to delete. You would need to either drop and recreate the constraints or delete the data that the Foreign Key references. Suppose you have the following tables dbo.Students ( StudentId StudentName StudentTypeId ) dbo.StudentTypes ( StudentTypeId StudentType ) … Read more

How do I delete all the duplicate records in a MySQL table without temp tables

Add Unique Index on your table: ALTER IGNORE TABLE `TableA` ADD UNIQUE INDEX (`member_id`, `quiz_num`, `question_num`, `answer_num`); Another way to do this would be: Add primary key in your table then you can easily remove duplicates from your table using the following query: DELETE FROM member WHERE id IN (SELECT * FROM (SELECT id FROM … Read more