如何在symfony2.0中编写mysql查询?

时间:2012-12-04 08:31:08

标签: mysql symfony

我有一个mysql查询,但我不知道如何在symfony2.0中进行查询。

查询:

SELECT a.id, a.name,
FROM `ms_musiccategory` a
LEFT OUTER JOIN `ms_musiccategory` b ON a.parent_Id = b.id
ORDER BY coalesce( b.name, a.name ) , a.name

1 个答案:

答案 0 :(得分:-2)

可能是你这样写的:

 $con = $this -> getEntityManager() -> getConnection();

 $st = $con -> prepare(' SELECT a.* FROM `tablename` a LEFT OUTER JOIN `tablename` b ON a.parent_Id = b.id ORDER BY coalesce( b.name, a.name ) , a.name');

 $st -> execute();

 $list = $st -> fetchAll(); 

我希望这对你有帮助.....