简体   繁体   中英

JOIN in JOIN with Zend

how would you create this query using Zend Framework's Zend_Db_Select

SELECT movie.*, count(DISTINCT similar.tag) as shared_tags FROM movie INNER JOIN 
    ( tagged AS this_movie INNER JOIN tagged AS similar USING (tag) )
    ON similar.movie = movie.id
WHERE this_movie.movie=<current_movie_id>
AND   movie.id != this_movie.movie
GROUP BY movie.id
ORDER BY shared_tags DESC
 $query = ("SELECT movie.*, count(DISTINCT similar.tag) as shared_tags 
   FROM movie 
   INNER JOIN (tagged AS this_movie 
               INNER JOIN tagged AS similar USING (tag) )     
     ON similar.movie = movie.id 
   WHERE this_movie.movie=<current_movie_id> 
   AND movie.id != this_movie.movie 
   GROUP BY movie.id ORDER BY shared_tags DESC ");  
 mysql_query('$query') or die(mysql_error()); 

Should you use any params in your query don't forget to escape all params with

$param = mysql_real_escape_string($param);

Before feeding them to the sql_query or you'll get bitten by SQL-injection attacks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM