syrkull
syrkull

Reputation: 2344

Showing a combined tables in SQL

Lets say that I have a MySQL table that looks like this :

 BookTitle    Chapter    DateAdded  
  Book1          3       2012-12-15
  Book1          2       2012-12-16 
  Book1          1       2012-12-15
  Book2          2       2012-12-16

I want to show it in HTML so it can look like this :

 Book2      2
 Book1      2,3,1  

Basically I want to get rid of the title of the book if existed! and group all the chapters together and sort them by the date

I was thinking of using Group By but all my experiments did not work. Please give me a solution or an advice. I am able to use PHP and MySQL I am currently using a Smarty template on this project.

Upvotes: 1

Views: 58

Answers (1)

John Woo
John Woo

Reputation: 263933

Actually, you can do this in MySQL. Use GROUP_CONCAT function.

SELECT BookTitle, GROUP_CONCAT(Chapter) ChapterList
FROM tableName
GROUP BY BookTitle

Other Source

Upvotes: 3

Related Questions