开发者

MySQL Join Multiple Table

News

nID  nTitle
-----------
1    test

Keyword

kID kWord nID
--------------
 1   abc   1
 2   def   1
 3   ghj   1

So i fetch it like

$开发者_JAVA技巧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>";
}

As you can see, this will output 3 rows of same title with 3 different keyword. Output :

test - abc
test - def
test - ghj

What i would like to have it

test - abc def ghj


SELECT GROUP_CONCAT(kWord) FROM News NATURAL JOIN Keyword GROUP BY News.nID

But what's the interest ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜