在我的 Joomla 2.5 模板中,我使用以下 JOIN 查询从两个表中获取一些信息(#_content 和 #_attachments)
->select(array('a.description','a.display_name','a.parent_id','a.filename','a.url', 'b.title', 'b.id','b.state','c.title'))
->from('#__attachments AS a')
->join('INNER', '#__content AS b ON (a.parent_id = b.id)')
->where("b.state = 1")
->order("RAND()");
如何为表#_类别添加一个连接以获得类别标题(此处命名为“c.title”。)?类别行的 Id 在 #_content 中保存为 catid。我希望作业应该类似于:
->join('INNER', '#__content AS b ON (c.id = b.catid)')
谢谢
托尼
最佳答案
您需要添加:
->join('INNER', '#__categories AS c ON b.catid = c.id')
如果content
中的项目可能没有附件并用作主表content
,请考虑为附件
添加LEFT JOIN
关于mysql - Joomla DB 查询连接三个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15448670/