我有一个这样的表orders
-
id | bookId
------------
1 3
2 2
3 1
而这个
books
-bookId | book
---------------
1 bookA
2 bookB
3 bookC
当我这样做时,他们能以何种方式获取
book
下的bookId
列select * from orders where id = '1'
这样的结果将是-
id | bookId
------------
1 bookC <------- bookC instead of 3
最佳答案
您需要将bookid
表中orders
列上的表JOIN映射到bookid
表中的books
列:
select o.id, b.book as bookId
from orders o
inner join books b
on o.bookid = b.bookid
where o.id = 1;
关于mysql - 从多个表中获取结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17374126/