<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Fri May 24 22:22:05 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DC-802/DC-802.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DC-802] Alias in select and having</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-802</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;i have query&lt;/p&gt;

&lt;p&gt;$q = Doctrine_Query::create()&lt;br/&gt;
            -&amp;gt;select(&apos;g.&lt;b&gt;,gp.&lt;/b&gt;,st.&lt;b&gt;,np.&lt;/b&gt;,v.&lt;b&gt;,s.&lt;/b&gt;,max(gp.card_date) as md&apos;)&lt;br/&gt;
            -&amp;gt;from(&apos;gragdans as g&apos;)&lt;br/&gt;
            -&amp;gt;innerJoin(&apos;g.Pribs_ gp&apos;)&lt;br/&gt;
            -&amp;gt;leftJoin(&apos;gp.Streets_ st&apos;)&lt;br/&gt;
            -&amp;gt;leftJoin(&apos;gp.Viddocs_ v&apos;)&lt;br/&gt;
            -&amp;gt;leftJoin(&apos;gp.Sobits_ s&apos;)&lt;br/&gt;
            -&amp;gt;leftJoin(&apos;st.Npunkts_ np&apos;)&lt;br/&gt;
            -&amp;gt;where(&apos;g.grid in &apos;.$idlst,1)&lt;br/&gt;
            -&amp;gt;orderby(&apos;fam&apos;)&lt;br/&gt;
            -&amp;gt;having(&apos;gp.card_date=md&apos;);&lt;/p&gt;

&lt;p&gt;When it runs i have error:&lt;/p&gt;

&lt;p&gt;&amp;lt;b&amp;gt;Fatal error&amp;lt;/b&amp;gt;:  Uncaught exception&lt;br/&gt;
&apos;Doctrine_Connection_Mysql_Exception&apos; with message &apos;SQLSTATE&lt;span class=&quot;error&quot;&gt;&amp;#91;42S22&amp;#93;&lt;/span&gt;:&lt;br/&gt;
Column not found: 1054 Unknown column &apos;md&apos; in &apos;having clause&apos;&apos; in Z:&lt;br/&gt;
\home\new\www\system\application\plugins\doctrine\lib\Doctrine&lt;br/&gt;
\Connection.php:1082&lt;/p&gt;

&lt;p&gt;SQL for it looks like:&lt;/p&gt;

&lt;p&gt;SELECT g.grid AS g_&lt;em&gt;grid, g.fam AS g&lt;/em&gt;&lt;em&gt;fam, g.nam AS g&lt;/em&gt;_nam, g.otc AS&lt;br/&gt;
g_&lt;em&gt;otc, g.date_rogd AS g&lt;/em&gt;&lt;em&gt;date_rogd, g.gosgrid AS g&lt;/em&gt;_gosgrid,&lt;br/&gt;
g.rogd_place AS g_&lt;em&gt;rogd_place, g.pol AS g&lt;/em&gt;_pol, g.reg_date AS&lt;br/&gt;
g_&lt;em&gt;reg_date, g.deesp AS g&lt;/em&gt;&lt;em&gt;deesp, p.pribid AS p&lt;/em&gt;_pribid, p.grid AS&lt;br/&gt;
p_&lt;em&gt;grid, p.strid AS p&lt;/em&gt;&lt;em&gt;strid, p.hom AS p&lt;/em&gt;&lt;em&gt;hom, p.cor AS p&lt;/em&gt;_cor, p.kva&lt;br/&gt;
AS p_&lt;em&gt;kva, p.reg_date AS p&lt;/em&gt;&lt;em&gt;reg_date, p.vidid AS p&lt;/em&gt;_vidid, p.pas_ser&lt;br/&gt;
AS p_&lt;em&gt;pas_ser, p.pas_no AS p&lt;/em&gt;&lt;em&gt;pas_no, p.org_name AS p&lt;/em&gt;_org_name,&lt;br/&gt;
p.pas_date AS p_&lt;em&gt;pas_date, p.sobid AS p&lt;/em&gt;_sobid, p.reg_expire AS&lt;br/&gt;
p_&lt;em&gt;reg_expire, p.card_date AS p&lt;/em&gt;&lt;em&gt;card_date, s.strid AS s&lt;/em&gt;_strid,&lt;br/&gt;
s.npid AS s_&lt;em&gt;npid, s.name AS s&lt;/em&gt;&lt;em&gt;name, v.vidid AS v&lt;/em&gt;_vidid, v.name AS&lt;br/&gt;
v_&lt;em&gt;name, s2.sobid AS s2&lt;/em&gt;&lt;em&gt;sobid, s2.cod_s AS s2&lt;/em&gt;_cod_s, s2.cod_oi AS&lt;br/&gt;
s2_&lt;em&gt;cod_oi, s2.name AS s2&lt;/em&gt;&lt;em&gt;name, n.npid AS n&lt;/em&gt;&lt;em&gt;npid, n.name AS n&lt;/em&gt;_name,&lt;br/&gt;
n.sid AS n_&lt;em&gt;sid, MAX(p.card_date) AS p&lt;/em&gt;_0 FROM gragdans g INNER JOIN&lt;br/&gt;
prib p ON g.grid = p.grid LEFT JOIN streets s ON p.strid = s.strid&lt;br/&gt;
LEFT JOIN viddoc v ON p.vidid = v.vidid LEFT JOIN sobit s2 ON p.sobid&lt;br/&gt;
= s2.sobid LEFT JOIN npunkt n ON s.npid = n.npid WHERE (g.grid in (4,&lt;br/&gt;
13, 19, 20)) HAVING p.card_date=md ORDER BY g.fam&lt;/p&gt;

&lt;p&gt;But i need Query looks like:&lt;/p&gt;

&lt;p&gt;SELECT g.grid AS g_&lt;em&gt;grid, g.fam AS g&lt;/em&gt;&lt;em&gt;fam, g.nam AS g&lt;/em&gt;_nam, g.otc AS&lt;br/&gt;
g_&lt;em&gt;otc, g.date_rogd AS g&lt;/em&gt;&lt;em&gt;date_rogd, g.gosgrid AS g&lt;/em&gt;_gosgrid,&lt;br/&gt;
g.rogd_place AS g_&lt;em&gt;rogd_place, g.pol AS g&lt;/em&gt;_pol, g.reg_date AS&lt;br/&gt;
g_&lt;em&gt;reg_date, g.deesp AS g&lt;/em&gt;&lt;em&gt;deesp, p.pribid AS p&lt;/em&gt;_pribid, p.grid AS&lt;br/&gt;
p_&lt;em&gt;grid, p.strid AS p&lt;/em&gt;&lt;em&gt;strid, p.hom AS p&lt;/em&gt;&lt;em&gt;hom, p.cor AS p&lt;/em&gt;_cor, p.kva&lt;br/&gt;
AS p_&lt;em&gt;kva, p.reg_date AS p&lt;/em&gt;&lt;em&gt;reg_date, p.vidid AS p&lt;/em&gt;_vidid, p.pas_ser&lt;br/&gt;
AS p_&lt;em&gt;pas_ser, p.pas_no AS p&lt;/em&gt;&lt;em&gt;pas_no, p.org_name AS p&lt;/em&gt;_org_name,&lt;br/&gt;
p.pas_date AS p_&lt;em&gt;pas_date, p.sobid AS p&lt;/em&gt;_sobid, p.reg_expire AS&lt;br/&gt;
p_&lt;em&gt;reg_expire, p.card_date AS p&lt;/em&gt;&lt;em&gt;card_date, s.strid AS s&lt;/em&gt;_strid,&lt;br/&gt;
s.npid AS s_&lt;em&gt;npid, s.name AS s&lt;/em&gt;&lt;em&gt;name, v.vidid AS v&lt;/em&gt;_vidid, v.name AS&lt;br/&gt;
v_&lt;em&gt;name, s2.sobid AS s2&lt;/em&gt;&lt;em&gt;sobid, s2.cod_s AS s2&lt;/em&gt;_cod_s, s2.cod_oi AS&lt;br/&gt;
s2_&lt;em&gt;cod_oi, s2.name AS s2&lt;/em&gt;&lt;em&gt;name, n.npid AS n&lt;/em&gt;&lt;em&gt;npid, n.name AS n&lt;/em&gt;_name,&lt;br/&gt;
n.sid AS n__sid, MAX(p.card_date) AS md FROM gragdans g INNER JOIN&lt;br/&gt;
prib p ON g.grid = p.grid LEFT JOIN streets s ON p.strid = s.strid&lt;br/&gt;
LEFT JOIN viddoc v ON p.vidid = v.vidid LEFT JOIN sobit s2 ON p.sobid&lt;br/&gt;
= s2.sobid LEFT JOIN npunkt n ON s.npid = n.npid WHERE (g.grid in (4,&lt;br/&gt;
13, 19, 20)) group by fam HAVING p.card_date=md&lt;/p&gt;

&lt;p&gt;This query run fine and give me what i need.&lt;/p&gt;

&lt;p&gt;Doctrine dont use &apos;md&apos; alias instead it convert it to &apos;p__0&apos; &lt;/p&gt;</description>
                <environment>Windows XP sp3 </environment>
            <key id="11692">DC-802</key>
            <summary>Alias in select and having</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="2" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/critical.png">Critical</priority>
                    <status id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/open.png">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="skyranger">Vasiliy Altunin</reporter>
                        <labels>
                    </labels>
                <created>Wed, 28 Jul 2010 22:39:58 +0000</created>
                <updated>Sat, 7 Aug 2010 15:39:30 +0000</updated>
                                                                            <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>