I crawled some datas from a web then directly save them in database, so I got $title, $url, and $author. But, the number of $author for one title can more than 1 data. So, I separated $author from $title and $url. all id is auto increment.
tb_wrapper tb_author
================= ==================
|id| title | url| |id|author|$title|
================= ==================
|1 |titleA |urlA| | 1| A |titleA|
================= | 2| B |titleA|
===================
in the other process(from document files that I got that their filename is same with $title), i have a table also that contain $title : tb_doc
======================
|id | content | title|
======================
|1 | contentA|titleA|
======================
I need to get datas from those 3 tables, so I can get the result like :
titleA has URLA contentA and author A and B
here’s the code :
$query = mysql_query("SELECT
tb_wrapper.url,
tb_wrapper.title,
tb_author.title,
tb_author.author,
tb_doc.content,
tb_doc.title
FROM
tb_doc
INNER JOIN tb_wrapper ON tb_doc.title = tb_wrapper.title
INNER JOIN tb_author ON tb_wrapper.title = tb_author.title ");
But, from that, I got duplicate result, author A and B are separated. please, help me, what join I have to do ? thank you very much 🙂
Use
GROUP_CONCATlike so:SQL Fiddle Demo