Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Urgent: two authors for the same book

New Here ,
Jul 27, 2011 Jul 27, 2011

I have a database with three tables: books, authors and aux.

The books table stores the names of the books. The authors table stores the name of the authors. Table aux takes the id of the other two. I did this for the case of the same book has two or more authors

The query I did was the following:

SELECT authores.author, books.title
FROM aux
, authors, books
WHERE aux
.books_id = books.id AND aux.authors_id = authors.id
ORDER BY books
.title ASC

How do I show the two authors for the same book?

For now, I'm using a simple table:


<table border="1" cellpadding="1" cellspacing="1">
 
<tr>
   
<td>author</td>
   
<td>title</td>
 
</tr>
 
<?php do { ?>
   
<tr>
     
<td><?php echo $row_rsBooks['author']; ?></td>
     
<td><?php echo $row_rsBooks['title']; ?></td>
   
</tr>
   
<?php } while ($row_rsBooks = mysql_fetch_assoc($rsBooks)); ?>
</table>


Thus, the table presents two results for the same book, instead of uniting the two authors of the same book.
TOPICS
Server side applications
437
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 27, 2011 Jul 27, 2011

Book table has unique id for each entry. Author table has id for each book. JOIN your tables based on matching id to display author(s) for the book.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 27, 2011 Jul 27, 2011
LATEST

Thanks for the reply.

In the meantime, got what I wanted. The expression looks like this:

SELECT livros.titulo, GROUP_CONCAT(autores.autor SEPARATOR ',') AS Autores
FROM livros INNER JOIN aux ON aux.livros_id = livros.id INNER JOIN autores ON aux.autores_id = autores.id
GROUP BY livros.titulo

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines