nID nTitle
-----------
1 test
kID kWord nID
--------------
1 abc 1
2 def 1
3 ghj 1
所以我像
一样抓取它$sql = mysql_query("SELECT *
FROM news as n,
keyword as k
WHERE n.nID = k.nID");
PHP
while($row = mysql_fetch_array($sql)) {
echo "<div>".$row['nTitle']." - ".$row['kWord']."</div>";
}
正如您所看到的,这将输出3行相同的标题和3个不同的关键字。 输出:
test - abc
test - def
test - ghj
我想拥有它
test - abc def ghj
答案 0 :(得分:1)
SELECT GROUP_CONCAT(kWord) FROM News NATURAL JOIN Keyword GROUP BY News.nID
但是有什么兴趣?