0

我有下表:

CREATE TABLE IF NOT EXISTS `article` (
  `article_id` int(11) NOT NULL,
  `language_id` int(11) NOT NULL,
  `category_id` int(11) NOT NULL,
  `article_title` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `article_body` varchar(8192) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `meta_description` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `meta_keyword` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `article_main_image` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `promote` bit(1) NOT NULL DEFAULT b'0',
  `created` datetime NOT NULL,
  `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `deleted` bit(1) NOT NULL DEFAULT b'0',
  `published` bit(1) NOT NULL DEFAULT b'1',
  `user_id` int(11) NOT NULL,
  PRIMARY KEY (`article_id`,`language_id`),
  KEY `article_title` (`article_title`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

lagnuage_id:

英语 = 1

阿拉伯语 = 2

俄语 = 3

我愿意select * where language_id = 1 limit by 10,但如果语言列相同,则将它们合二为一article_id。例如:

(1, 1, 0, 'qwq', 'da sdsad as da ds', 'asd sa d', 'as dsadasd as d sa', '', b'0', '2013-06-20 11:01:32', '2013-06-20 08:01:32', b'0', b'1', 0),
(1, 2, 0, '????????', '?? ??? ??? ??? ???', '?? ??? ??? ? ???? ', '??? ??? ?? ???? ?? ???? ', '', b'0', '2013-06-20 11:01:32', '2013-06-20 08:01:32', b'0', b'1', 0),
(1, 3, 0, 'rrrrrrrrrrr', 'rrrr', 'rrrrrrrrrrrrrrrrr', 'rrrrrrrrrrrrrrrrrrrrrrrrrr', '', b'0', '2013-06-20 11:01:32', '2013-06-20 08:01:32', b'0', b'1', 0),

我想选择这样的行:

(1, 1-2-3, 0, 'qwq', 'da sdsad as da ds', 'asd sa d', 'as dsadasd as d sa', '', b'0', '2013-06-20 11:01:32', '2013-06-20 08:01:32', b'0', b'1', 0),

注意语言 id 是如何连接的;我希望能够知道这篇文章可以使用哪些语言。

4

1 回答 1

0

使用GROUP BY并且GROUP_CONCAT我能够解决我的问题:

SELECT  `article_id` , GROUP_CONCAT(  `language_id` ) , ..,..,..,..
FROM  `article` 
GROUP BY  `article_id` 
LIMIT 0 , 30
于 2013-06-24T12:06:29.437 回答