forked from slick/slick
-
Notifications
You must be signed in to change notification settings - Fork 12
Unions
szeiger edited this page Sep 13, 2010
·
1 revision
Queries of compatible types can be combined to unions with the union
and unionAll
methods:
object Managers extends Table[(Int, String, String)]("managers") {
def id = column[Int]("id")
def name = column[String]("name")
def department = column[String]("department")
def * = id ~ name ~ department
}
object Employees extends Table[(Int, String, Int)]("employees") {
def id = column[Int]("id")
def name = column[String]("name")
def manager = column[Int]("manager", O.NotNull)
def * = id ~ name ~ manager
}
...
val q1 = for(m <- Managers if m.department === "IT") yield m.id ~ m.name
val q2 = for(e <- Employees) yield e.id ~ e.name
val q3 = for(id ~ name <- q1 union q2) yield id ~ name
unionAll
simply combines the rows produced by both queries, whereas union
filters out duplicate rows.