tags:

views:

107

answers:

3

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            1   
6            1

But I want it to return:

film_id
  7
  6

How do I return only 1 colomn?

+12  A: 

To do just move your count filed in you having clause will do 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  
Pranay Rana
`GROUP BY anime_id,COUNT(film_id)` I'd say...
Wrikken
i think this will make no difference because goal is to remove count field form the select and have to select rows where film_id==1
Pranay Rana
thanks alot pranay
meotimdihia
A: 

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')));

Leo
A: 

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
Madhivanan
thanks alot nadguvanan
meotimdihia