1

我需要在查询中添加一个额外的连接,但我不确定要加入什么。

SELECT DISTINCT * FROM {$this->prefix}category c 
   LEFT JOIN {$this->prefix}category_description cd 
      ON (c.category_id = cd.category_id) 
   LEFT JOIN {$this->prefix}category_to_store c2s 
      ON (c.category_id = c2s.category_id) 
WHERE c.category_id = '" . (int)$category_id . "' 
   AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' 
   AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' 
   AND c.status = '1' 

我现在需要通过如下列值加入我的 url_alias 表:

SELECT keyword FROM {$this->prefix}url_alias 
WHERE query = 'category_id=" . (int)$category_id . "'

-- 编辑澄清 --

这适用于需要通过将关键字添加到现有类别/产品/制造商查询来简化 url 重写的 OpenCart 项目。

4

1 回答 1

1

这个怎么样:

SELECT DISTINCT * FROM {$this->prefix}category c 
  LEFT JOIN {$this->prefix}category_description cd 
    ON (c.category_id = cd.category_id) 
  LEFT JOIN {$this->prefix}category_to_store c2s 
    ON (c.category_id = c2s.category_id) 

  LEFT JOIN {$this->prefix}url_alias u 
    ON u.query = CONCAT('category_id=', c.category_id)

WHERE c.category_id = '" . (int)$category_id . "' 
  AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' 
  AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' 
  AND c.status = '1' 
于 2013-07-19T05:35:27.300 回答