假设我的数据库中有这些表:
items
categories
weapons
shields
swords
我需要创建一个这样的连接:
SELECT items.*, {swords}.*
FROM items
INNER JOIN categories
ON categories.id = items.category_id # <-- here I know that the item is a sword
INNER JOIN {swords}
ON {swords}.item_id = item.id
WHERE items.id = 12
但是
{swords}
部分是动态的,因为我发现一个项目是一个
检查
categories.name
现场。
如果
类别.名称
是“
盾
“对此:
SELECT items.*, shields.*
FROM items
INNER JOIN categories
ON categories.id = items.category_id
INNER JOIN shields
ON shields.item_id = item.id
WHERE items.id = 13
我曾经
{
和
}
swords
把它当作变量来表示