Getting a result from 2 joined tables
Posted: Sun Apr 18, 2004 6:59 pm
Hi everybody ..
I have two tables and want to join them in a query to produce a summary report.
The Query is :
The result will be :
Actually I need to eleminate those duplicated rows and combine their categories to produce such result like this :
So any idea of how to do this in MySQL (without using PHP, Perl ..etc.) ?
Thanks
Mishal
I have two tables and want to join them in a query to produce a summary report.
Code: Select all
Table_1
====================
article_id | author
====================
10 | Tom
11 | Dave
12 | Adam
13 | Peter
====================
Table_2
====================
article_id | category
====================
10 | Ethics
10 | Social
11 | Sports
12 | Entertainment
12 | Jokes
12 | Amusing
13 | Health
====================Code: Select all
SELECT Table_1.article_id, Table_1.author, Table_2.category
FROM Table_1, Table_2
WHERE Table_1.article_id=Table_2.article_id
ORDER BY article_id;Code: Select all
==========================================
article_id | author | category
==========================================
10 | Tom | Ethics
10 | Tom | Social
11 | Dave | Sports
12 | Adam | Entertainment
12 | Adam | Jokes
12 | Adam | Amusing
13 | Peter | Health
==========================================Code: Select all
===============================================================
article_id | author | category
===============================================================
10 | Tom | Ethics, Social
11 | Dave | Sports
12 | Adam | Entertainment, Jokes, Amusing
13 | Peter | Health
===============================================================Thanks
Mishal