P
P
Pios882018-07-04 14:36:09
MySQL
Pios88, 2018-07-04 14:36:09

How to set up a one-to-many relationship between tables in MySQL?

There is a database with two tables:
1. Author - id | name
2. Book - id | author_id | title | description | image (the last one is just a url)
I configured via phpmyadmin so that now the author_id values ​​in the book table are highlighted and when I click on them, I get a row with the desired author from the author table. That is, I made a connection "many to one".
But I also need to make a one-to-many relationship so that by clicking on the author's id, I get rows with all his books from the book table.
And then the skiing felts do not go, or I don’t understand something. In one direction, everything is easy to set up in phpmyadmin, but in the opposite direction it’s impossible to make a connection.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zxscv, 2018-07-04
@zxscv

Why are you setting up phpmyadmin? Write SQL examples
SELECT * FROM Book WHERE author_id = XX get books by one author
SELECT * FROM Book INNER JOIN Author ON Author.author_id = Book.id WHERE Book.id= XX get book data including author

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question