Question

I am trying to delete some records to optimize the data.

If delete can replace select *, that's a good way to solve trouble. for example.

select *
FROM  `wp_term_relationships`, wp_terms,wp_term_taxonomy  where  
'wp_term_relationships`.`term_taxonomy_id`=wp_terms.term_id and wp_terms.term_id=wp_term_taxonomy.term_id
and   `wp_term_relationships`.`object_id` 
BETWEEN 1154 
AND 11560;

I got many data.

I can't put delete to replace select *. I only delete data one by one

I have to write down all of records and have to know which keys are related with "object_id between 1154 and 11560".

it is tough to see...

Was it helpful?

Solution

This will delete records from both the table (what select return)

DELETE 
FROM `wp_term_relationships`, `wp_terms` , `wp_term_taxonomy`
USING  `wp_term_relationships`, `wp_terms`, `wp_term_taxonomy`
WHERE
'wp_term_relationships`.`term_taxonomy_id`=`wp_terms`.`term_id`
AND `wp_terms.term_id`=`wp_term_taxonomy`.`term_id`
AND `wp_term_relationships`.`object_id` BETWEEN 1154 AND 11560;

also try using JOIN clause

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top