MySQL - ID无法正确显示

时间:2015-02-25 16:30:14

标签: mysql inner-join

我有一个表格authorshelfbook该图书的外键为author_idshelf_id。 在作者中,数据为1=Jose2=William Shakespeare。 在货架上,它是1=History2=Science。 我添加它的ID分别是1,1。但是当我使用内连接时。它显示为ScienceWilliam Shakespeare。但当我select * from book时,它显示为1和1.

这是我的查询

select b.book_title, a.author_firstname, ' ' ,a.author_lastname,b.book_description,s.shelf_description,b.book_quantity 
from book b
inner join author a 
on b.book_id= a.author_id
inner join shelf s 
on b.book_id=s.shelf_id

1 个答案:

答案 0 :(得分:0)

这是我的正确查询

select 
    b.book_title, a.author_firstname, ' ' ,a.author_lastname) Author ,b.book_description,s.shelf_description,b.book_quantity
     from book b 
     inner join author a 
     on b.author_id= a.author_id
     inner join shelf s
     on b.shelf_id=s.shelf_id

它未对齐的原因是因为book_id的值等于author_id,将覆盖显示。