Home > database >  Consult a great god a query problem, have structure data and ideas
Consult a great god a query problem, have structure data and ideas

Time:09-21

Select * from test_news;
Select * from test_news_category



Table structure:
The CREATE TABLE ` test_news ` (
` id ` int (11), NOT NULL AUTO_INCREMENT,
DEFAULT NULL ` name ` varchar (50),
The PRIMARY KEY (` id `)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- Records of test_news
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
INSERT INTO ` test_news ` VALUES (' 1 ', '1' news);
INSERT INTO ` test_news ` VALUES (' 2 ', '2' news);


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The CREATE TABLE ` test_news_category ` (
` id ` int (11), NOT NULL AUTO_INCREMENT,
DEFAULT NULL ` newsid ` int (50),
` cateid ` int (11) the DEFAULT NULL,
The 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');

CodePudding user response:

What kind of results you want, can give a sample?

CodePudding user response:

Upstairs, a great god, and you see me that figure, wrote, query news 2, demand is also on the chart,

CodePudding user response:

Done!

Select * from test_news
Where
Not the EXISTS (
Select * from test_news_category where newsid=test_news. Id and cateid not in (1, 2)
)

  • Related