<div class='quotetop'>QUOTE </div>
Suppose i have these two tables. in buddies table buddy1 or buddy2 is the ID of users table . I want a query that will delete the buddies ID if buddy1 or buddy2 doesnt not exist in users table
CREATE TABLE `buddies` (
`id` int(11) NOT NULL auto_increment,
`buddy1` int(11) NOT NULL,
`buddy2` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Buddies table' AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL auto_increment,
`login` varchar(30) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `login` (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='users' AUTO_INCREMENT=1 ;[/b]
`id` int(11) NOT NULL auto_increment,
`buddy1` int(11) NOT NULL,
`buddy2` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Buddies table' AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL auto_increment,
`login` varchar(30) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `login` (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='users' AUTO_INCREMENT=1 ;[/b]
Comment