Mysql。根据1个表中的列,从3个不同的表中选择数据
以下是我想做的: 我有三张桌子:音乐、摄影、文字 每个表都有不同的列Mysql。根据1个表中的列,从3个不同的表中选择数据,mysql,select,join,Mysql,Select,Join,以下是我想做的: 我有三张桌子:音乐、摄影、文字 每个表都有不同的列 Table "musicItems" id Owner_id audioId url duration Table "photoItems" id albumId userId photoId url Table "textItems" id msgText 我还有一张桌子 "footprints" id itemType itemId 我需要从表封
Table "musicItems"
id
Owner_id
audioId
url
duration
Table "photoItems"
id
albumId
userId
photoId
url
Table "textItems"
id
msgText
我还有一张桌子
"footprints"
id
itemType
itemId
我需要从表封装外形中重新筛选最后30个项目,所有属性取决于itemType和itemId。我该怎么做呢?我假设ItemType列包含ItemID引用的表名
SELECT *
FROM footprints fp
LEFT OUTER JOIN musicItems mi ON mi.ID = fp.itemID AND fp.ItemType = 'musicItems'
LEFT OUTER JOIN photoItems pi ON pi.ID = fp.itemID AND fp.ItemType = 'photoItems'
LEFT OUTER JOIN textItems ti ON ti.ID = fp.itemID AND fp.ItemType = 'textItems'
LIMIT 30
你能详细说明一下这些列是如何排列的吗?例如,哪些footprints列与哪个musicitems列排列在一起?另外,我相信您正在寻找执行左/内联接。请看您需要阅读联接语法:您可以从每个表中发布5行与示例相关的数据吗?Brad Christie,footprints表包含列itemType,该列可以是:1、2或3,它指向包含id=footprints.itemId的项目信息的表