Table of Contents

Delete SQL rows where IDs do not have a match from another table

	//Table name
	$employee = $wpdb->prefix . "innovs_employee";
    $wp_user = $wpdb->prefix . "users";

	// SQL Juery
    $sql = "DELETE FROM $employee WHERE NOT EXISTS(SELECT NULL FROM $wp_user u WHERE u.ID = userID)";
    $wpdb->query($sql);

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

Leave a Comment

Your email address will not be published.

Related Posts