select * from test_news;
select * from test_news_category

表結構:
CREATE TABLE `test_news` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of test_news
-- ----------------------------
INSERT INTO `test_news` VALUES ('1', '新聞1');
INSERT INTO `test_news` VALUES ('2', '新聞2');
--------------------------------
CREATE TABLE `test_news_category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`newsid` int(50) DEFAULT NULL,
`cateid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of test_news_category
-- ----------------------------
INSERT INTO `test_news_category` VALUES ('1', '1', '1');
INSERT INTO `test_news_category` VALUES ('2', '1', '2');
INSERT INTO `test_news_category` VALUES ('3', '1', '3');
INSERT INTO `test_news_category` VALUES ('4', '2', '1');
INSERT INTO `test_news_category` VALUES ('5', '2', '2');
uj5u.com熱心網友回復:
您想要什么樣的結果,能給一個樣例嗎。uj5u.com熱心網友回復:
樓上大神,你看我那個圖,上面寫了啊,查詢新聞2來,需求也在那個圖上。uj5u.com熱心網友回復:
搞定!select * from test_news
where
not EXISTS(
select * from test_news_category where newsid=test_news.id and cateid not in (1,2)
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/60867.html
標籤:MySQL
上一篇:sqlite 多個資料庫怎么切換
