SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE TagMap ( ArticleID int, Tag varchar(64) ); INSERT INTO TagMap VALUES (1, 'Tag1'),(1, 'Tag2'),(3, 'Tag1'),(4, 'Tag1'); SELECT -- here we concatenate articles by tags count GROUP_CONCAT(ArticleID ORDER BY cnt DESC) FROM ( -- here we calculate different tags cout per article SELECT ArticleID, COUNT(DISTINCT Tag) cnt FROM TagMap WHERE Tag IN('Tag1', 'Tag2', 'Tag3') GROUP BY ArticleID ) t;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear