cicakman
cicakman

Reputation: 1990

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

$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

Upvotes: 0

Views: 110

Answers (1)

MatTheCat
MatTheCat

Reputation: 18761

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

But what's the interest ?

Upvotes: 1

Related Questions