title: MyBatis include same <sql> fragment multiple times for joined tables of same type
body: <h2>Update 2016-06-07 - see my answer below for solution</h2>
  <p>Trying to find out if there is a way to reuse same  fragment in one query.</p>
  <p>Consider this:</p>
  <pre><code>&lt;sql id=&quot;personFields&quot;&gt;
      per.id                  person_id,
      per.created_at          person_created_at,
      per.email_address       person_email_address,
      per.first_name          person_first_name,
      per.last_name           person_last_name,
      per.middle_name         person_middle_name
  &lt;/sql&gt;
  </code></pre>
  <p>The &quot;per.&quot; alias is used to avoid column name clashing when using in queries with muiltiple joined tables.
  It is included like this:</p>
  <pre><code>SELECT
  &lt;include refid=&quot;com.acme.data.mapper.PersonMapper.personFields&quot;/&gt;
  FROM Person per
  </code></pre>
  <p>The problem is that it cannot be used more than once per query because we have the &quot;per.&quot; alias.</p>
  <p>Would be great to have something like this:</p>
  <pre><code>&lt;sql id=&quot;personFields&quot;&gt;
      #{alias}.id                  #{alias}_person_id,
      #{alias}.created_at          #{alias}_person_created_at,
      #{alias}.email_address       #{alias}_person_email_address,
      #{alias}.first_name          #{alias}_person_first_name,
      #{alias}.last_name           #{alias}_person_last_name,
      #{alias}.middle_name         #{alias}_person_middle_name
  &lt;/sql&gt;
  </code></pre>
  <p>And include it like this:</p>
  <pre><code>SELECT
  &lt;include refid=&quot;com.acme.data.mapper.PersonMapper.personFields&quot; alias=&quot;per1&quot;/&gt;,
  &lt;include refid=&quot;com.acme.data.mapper.PersonMapper.personFields&quot; alias=&quot;per2&quot;/&gt;
  FROM Person per1
  JOIN Person per2 ON per2.parent_id = per1.id
  </code></pre>