【问题标题】:MySQL finding rows in one table with information from anotherMySQL 在一个表中查找包含另一个表中的信息的行
【发布时间】:2012-07-07 02:03:20
【问题描述】:

目前,我有两个 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

我有我的朋友 ID,需要从表 1 中获取所有 pic_id,然后使用 pic_id 从表 2 中获取列(标题、颜色、详细信息)...

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

谢谢!

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    只需连接两个表。

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-06
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-25
      相关资源
      最近更新 更多