{"id":1105,"date":"2022-08-30T15:12:28","date_gmt":"2022-08-30T15:12:28","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/help-needed-converting-mysql-query-to-doctrine-query-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:12:28","modified_gmt":"2022-08-30T15:12:28","slug":"help-needed-converting-mysql-query-to-doctrine-query-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/help-needed-converting-mysql-query-to-doctrine-query-collection-of-common-programming-errors\/","title":{"rendered":"Help needed converting MySQL query to Doctrine Query-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to convert the following MySQL query which give me all clients who have not had an appointment for six months or more into a DQL query.<\/p>\n<pre><code>mysql&gt; select appt.lastDate, clients.firstname, clients.lastname\n-&gt; from (select max(gapmtDate) as lastDate,gapmtClient from groomappointments group by gapmtClient) as appt ,clients\n-&gt; where date_sub(CURDATE(), INTERVAL 6 MONTH)&gt;lastDate\n-&gt; AND clients.clientid = appt.gapmtClient;\n<\/code><\/pre>\n<p>I&#8217;ve tried to match this with the following but I receive an error stating that there is an unknown column g__0 in the where clause. Can anyone point out where I&#8217;m going wrong<\/p>\n<pre><code>public function noappointmentsforsixmonthsAction()\n{\n\n\n\n  $sixmonths=date('y-m-d',strtotime(\"-6 months\"));\n\n  $q=Doctrine_Query::create()\n  -&gt;select('MAX(g.gapmtDate) AS lastDate, c.firstname, c.lastname,g.gapmtClient')\n -&gt;from('PetManager_Model_Groomappointments g')\n -&gt;leftJoin('g.PetManager_Model_Clients c')\n -&gt;where('lastDate<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:28:18. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to convert the following MySQL query which give me all clients who have not had an appointment for six months or more into a DQL query. mysql&gt; select appt.lastDate, clients.firstname, clients.lastname -&gt; from (select max(gapmtDate) as lastDate,gapmtClient from groomappointments group by gapmtClient) as appt ,clients -&gt; where date_sub(CURDATE(), INTERVAL 6 MONTH)&gt;lastDate -&gt; AND [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1105","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1105"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1105\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}