MySQL在一个表中查找行,其中包含来自另一个表的信息


MySQL finding rows in one table with information from another

目前,我有两个MySQL表。

第一个表存储朋友和他的图片之间的关系。

表1

 id  |  pic_id  |  friend_id
----------------------------
 0   |  123     |  84589
 1   |  290     |  11390
 2   |  884     |  84589

表2

第二个表存储有关图片的详细信息...

id   |  pic_id  |  title   |  color  |  detail
----------------------------------------------
0    |  123     | hello    |  black  |  brush
1    |  124     | world    |   red   |  paint
2    |  884     | sample   |  green  |  star

我有我的friend_id,需要从表 1 中抓取所有pic_id,然后使用pic_id抓取表 2 中的列(标题、颜色、细节)......

我将如何在MySQL中执行此操作?

谢谢!

只需连接两个表即可。

SELECT b.title, b.color, b.detail
FROM table1 a INNER JOIN table2 b
        on a.pic_id = b.pic_id
WHERE friend_id = 84589