0
  $query = "SELECT DISTINCT t.task_id, e.url,e.error_id, p.page_rank, e.scan_status, e.url_is_route,e.url_is_route,e.forbidden_word,e.google_host_fail,e.google_cache_fail,e.google_title_fail,e.robots_noindex_nofollow,e.xrobots_noindex_nofollow,e.title_fetch_warn,e.h1_fail,e.h2_fail,e.h3_fail,e.h1_warn,e.h2_warn,e.h3_warn 
              FROM `error_report` AS e 
              INNER JOIN task_pages AS t ON t.task_id=e.task_id
              INNER JOIN `pages` AS p ON p.page_id=t.page_id
              WHERE t.task_id=" . $this->task_id ;

我希望查询仅由 t.task_id 区分。问题是当我添加更多字段时..查询不再不同。还有一种方法可以仅通过 t.task_id 选择不同的吗?

4

2 回答 2

3

而不是distinct使用group by

$query = "SELECT t.task_id, e.url,e.error_id, p.page_rank, e.scan_status, e.url_is_route,e.url_is_route,e.forbidden_word,e.google_host_fail,e.google_cache_fail,e.google_title_fail,e.robots_noindex_nofollow,e.xrobots_noindex_nofollow,e.title_fetch_warn,e.h1_fail,e.h2_fail,e.h3_fail,e.h1_warn,e.h2_warn,e.h3_warn 
          FROM `error_report` AS e 
          INNER JOIN task_pages AS t ON t.task_id=e.task_id
          INNER JOIN `pages` AS p ON p.page_id=t.page_id
          WHERE t.task_id=" . $this->task_id
          ."group by t.task_id";
于 2012-05-13T10:56:17.490 回答
1

如果添加更多字段,则应使用GROUP BYiirc。

请注意,您的额外字段应该是聚合,例如MINMAX等。MySQL 更宽容,并显示每个字段的第一个值(尽管显然不可靠)。

于 2012-05-13T10:59:19.337 回答