我有代码:
$query = "SELECT a.*, c.name as categoryname, c.id as categoryid
FROM #__table_one as a
LEFT JOIN #__table_two c ON c.id = a.catid";
$query .= " WHERE a.published = 1
AND a.access <= {$aid}
AND a.trash = 0
AND c.published =
AND c.access <= {$aid}
AND c.trash = 0";
我想为查询中的 a.publish,a.access和a.trash 添加第三个表格('__ some_table')。换句话说,我希望从另一个表中检索这些字段,而不是“ #__ table_one ”,但我不知道如何将 #__ some_table 合并到当前查询中
我想 JOIN 命令可以帮助我,但我不知道如何编写mysql
答案 0 :(得分:0)
//未经测试
$query = "SELECT a.*, c.name as categoryname, c.id as categoryid
FROM #__table_one as a
LEFT JOIN #__table_two c ON c.id = a.catid
LEFT JOIN #__table_three d ON d.id = a.some_id";