is there any way using DQL write a query that joins table with itself?
+1
A:
Remember, when writing DQL, you're not really writing any SQL yourself, you're talking to your object model at the ORM's level. So when you use 'JOIN' in DQL, you're referencing a relationship between entities, not actual tables.
So I would create a self-referencing relationship in an entity, then use DQL to join that relationship:
$em->createQuery('SELECT a FROM MyEntity a JOIN a.foo f WHERE f.bar = 'somevalue')
Bryan M.
2010-09-14 19:15:49
Thanks for your answer, but in my case I want to write this query : SELECT * FROM table as t1 LEFT JOIN table AS t2 ON t1.field1 = t2.field1 AND t1.field2 = t2.field2 AND t2.date > t1.date WHERE t2.id IS NULL. This query is used to select from list with equal field1 and field2 only one entity with biggest date field. Is there any way to write this query in DQL?
Ris90
2010-09-15 07:55:07
I solved this problem with help of Native SQL Query
Ris90
2010-09-15 10:34:12