Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8670933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:49:26+00:00 2026-06-12T18:49:26+00:00

I face a problem I would like to simplify : (quite sure, I’m doing

  • 0

I face a problem I would like to simplify : (quite sure, I’m doing it wrong in fact).

Wanted

I would like to count the number of users having an id = 1. In SQL language let’s say it is something like this :

SELECT COUNT(*) FROM users WHERE id = 1

Code

I’m using Slick in it’s “lifted” form, so here is my piece of code counting the users :

Query(Users.where( _.id === 1).length).first

Actually what happens here is that Slick alias ScalaQuery, is actually creating a subquery with the filter cause and then counting the results of the sub-request.

SELECT COUNT(*) FROM (SELECT * FROM users WHERE id = 1))

Seems like pretty big overhead for such a query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:49:28+00:00Added an answer on June 12, 2026 at 6:49 pm

    Not sure if this has changed from ScalaQuery to Slick, but try:

    val q = for{ 
      id <- Parameters[Int]
      t <- tableObject if t.id is id
    } yield t.id.count
    
    val cnt = q(someID).firstOption getOrElse 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the problem i face is , i would like to join these two queries.
I have 3d mesh and I would like to draw each face a 2d
I would like to ask a question regarding a strange behavior I face using
I often face the problem of wanting to add additional methods to classes I
I begin in Python language and face a problem with my script. On stackoverflow,
I face the following problem function book($memberid, $classid){ if (!book){ // update the db
Sometimes i face the following problem : string txt = con.Request.Params[Par_name].ToString();//the original par value
we have a classical 3-tier-architecture application. Now we face a little problem and we
My problem is certainly right on my face but I can't see it... I
The problem is when I face my camera down the z axis for example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.