How can one column in the result of a MySQL query be removed?
Example:
SELECT `film_id`,COUNT(film_id) AS COUNT FROM films_genres AS FilmsGenre
WHERE genre_id In (4)
GROUP BY film_id,COUNT
HAVING COUNT = 1
return:
film_id | COUNT
7 开发者_Go百科 1
6 1
But I want it to return:
film_id
7
6
How do I return only 1 colomn?
To do it, just move your "COUNT(film_id)
". Your HAVING
clause will do the work for you.
SELECT `film_id` FROM films_genres AS FilmsGenre
WHERE genre_id In (4)
GROUP BY anime_id,film_id
HAVING COUNT(film_id) = 1
This isn't phrased as a CakePHP question,although it's tagged as such.
However, in CakePHP:
$this->FilmGenre->find('list',array('fields'=>array('film_id','film_id','anime_id')));
or make use of derived table
SELECT film_id from
(
SELECT `film_id`,COUNT(film_id) AS COUNT FROM films_genres AS FilmsGenre
WHERE genre_id In (4)
GROUP BY anime_id,COUNT
HAVING COUNT = 1
) as t
精彩评论