title: How can I count number of rows returned by a join in Slick?
body: <p>When I try to do <code>Query(query.length).first</code> on a query, that represents a join of 2 tables which have several columns with the same names, I am getting malformed sql. Consider the example:</p>
  
  <pre><code>// in Main.scala
  import scala.slick.driver.MySQLDriver.simple._
  object Main extends App {
  
    object Houses extends Table[Long]("Houses") {
      def id = column[Long]("id")
      def * = id
    }
    object Rooms extends Table[(Long, Long)]("Rooms") {
      def id = column[Long]("id")
      def houseId = column[Long]("houseId")
      def * = id ~ houseId
    }
  
    val query = for {
      h &lt;- Houses
      r &lt;- Rooms
      if h.id === r.houseId
    } yield (h, r)
    println("QUERY: " + Query(query.length).selectStatement)
  }
  
  // in build.sbt
  scalaVersion := "2.10.2"
  
  libraryDependencies += "com.typesafe.slick" %% "slick" % "1.0.1"
  </code></pre>
  
  <p>This example generates the following SQL:</p>
  
  <pre><code>select x2.x3 from
    (select count(1) as x3 from 
      (select x4.`id`, x5.`id`, x5.`houseId` 
       from `Houses` x4, `Rooms` x5 where x4.`id` = x5.`houseId`) x6) x2
  </code></pre>
  
  <p>Which is clearly wrong and is rejected by MySQL because <code>id</code> column is duplicated in <code>select x4.id, x5.id</code> part.</p>
  
  <p>I could try to do the following:</p>
  
  <pre><code>query.list.size
  </code></pre>
  
  <p>but that will extract all the rows from the query and send them over the wire, which is going to hinder performance greatly.</p>
  
  <p>What am I doing wrong? Is there some way to fix it?</p>