MySQL natural search and like search I have written two queries for searching, but I want to simplify them as it seems needed.

def searching(term: String): List[String] = {
    DB.withConnection { implicit c =&gt;
      var list = List[String]()
      val pinfo = SQL("SELECT body FROM tableName WHERE body like {term} limit 0,14 ").on("term" -&gt; ("%" + term + "%"))()
      pinfo.map {
        row =&gt;
          list ::= row[String]("body")
      }
      val res = SQL("SELECT body FROM tableName WHERE MATCH (body) AGAINST ({term} IN BOOLEAN MODE) limit 0,14 ").on("term" -&gt; term)()
      res.map {
        row =&gt;
          list ::= row[String]("body")
      }
      return list.distinct
    }
  }
Since the two queries don't depend on each other,
and they both return the same column,
it seems you can UNION them.

I cannot test this, but it seems this should work:

  def searching(term: String): List[String] = {
    DB.withConnection { implicit c =&gt;
      val result = SQL(
        "SELECT body FROM tableName WHERE body like {liketerm} limit 0,14 " +
        "UNION " +
        "SELECT body FROM tableName WHERE " +
        "MATCH (body) AGAINST ({term} IN BOOLEAN MODE) limit 0,14 ").on(
          "liketerm" -&gt; ("%" + term + "%"),
          "term" -&gt; term
        )()
      result.map(row =&gt; row[String]("body")).distinct
    }
  }


Not only this is simpler,
running one query instead of two is more efficient.