Mysql 合并表数据后返回行
所以我有一个表,它是一个引用表,它有以下列Mysql 合并表数据后返回行,mysql,Mysql,所以我有一个表,它是一个引用表,它有以下列 (id, profileID, resourceID) sample rows (1, 1, 22) (2, 1, 23) (3, 22, 75) id是主键,resourceID指的是资源表中的resourceID 资源表列: (id, path) sample rows (22,'user/sam.jpg') (23,'user/ann.jpg') (75,'user/tom.jpg') 我需要先查询引用表,然后查询资源表。我想知道哪些资源属于
(id, profileID, resourceID)
sample rows
(1, 1, 22)
(2, 1, 23)
(3, 22, 75)
id
是主键,resourceID
指的是资源表中的resourceID
资源表列:
(id, path)
sample rows
(22,'user/sam.jpg')
(23,'user/ann.jpg')
(75,'user/tom.jpg')
我需要先查询引用表,然后查询资源表。我想知道哪些资源属于profileID=1,我希望得到以下结果:
(22,'user/sam.jpg')
(23,'user/ann.jpg')
请原谅我,因为这是我第一次在这个论坛上发表文章,我保证将来会更好地学习格式。使用join和where子句筛选profileID=1的数据集
select a.*,b.path
from reference a
join resource b on a.resourceID = b.id
where a.profileID = 1
使用join和where子句筛选profileID=1的数据集
select a.*,b.path
from reference a
join resource b on a.resourceID = b.id
where a.profileID = 1
使用连接where
select resource.id, resource.path from RESOURCE resource INNER JOIN REFERENCE_TABLE ref_table
resource.id=ref_table.resourceID
where ref_table.profile_id=1
与where一起使用join
select resource.id, resource.path from RESOURCE resource INNER JOIN REFERENCE_TABLE ref_table
resource.id=ref_table.resourceID
where ref_table.profile_id=1
这非常有效,我已经从这个例子中学到了更多。谢谢。这非常有效,我已经从这个例子中学到了更多。谢谢