0
votes

I have tables CATEGORY and QUESTIONS with category_id foreign_key I need to take 3 categories and 3 questions from this categories. How can I do it using slick 3.0.3?

P.S. Or, how to do it in mysql query

1

1 Answers

0
votes

Try it this way .

I assumed that your requirement is to fetch first 3 categories , and get one question for each category respectively.

val q = for {
          categories <- Tables.categories.take(3)
          groupedByCat <- Tables.questions.filter(_.catId === categories.id).groupBy(_.catId).map(_._1)
          questions<- Tables.questions.filter(_.catId === groupedByCat)
        } yield questions