foo
id | foo_value |
2 | 10 |
3 | 10 |
bar
id | bar_value |
2 | 1 |
3 | 1 |
4 | 1 |
5 | 1 |
id | bar_value |
4 | 1 |
5 | 1 |
ทำแบบนี้
SELECT * FROM `bar` WHERE `bar`.`id` NOT IN (SELECT `foo`.`id` FROM `foo`);
ปล. คำสั่งสร้างตาราง foo, bar
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; CREATE TABLE IF NOT EXISTS `foo` ( `id` int(11) NOT NULL, `foo_value` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `foo` (`id`, `foo_value`) VALUES (2, 10), (3, 10); CREATE TABLE IF NOT EXISTS `bar` ( `id` int(11) NOT NULL, `bar_value` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `bar` (`id`, `bar_value`) VALUES (2, 1), (3, 1), (4, 1), (5, 1); |
ไม่มีความคิดเห็น:
แสดงความคิดเห็น