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 7792815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:18:07+00:00 2026-06-01T22:18:07+00:00

Having the following query template to select all: val q = for { a

  • 0

Having the following query template to select all:

val q = for {
  a <- Parameters[Int]
  b <- Parameters[Int]
  t <- T if t.a == a && t.b == b
  _ <- Query.orderBy(t.c, t.d)
} yield t

I need to modify it to select the very first (with minimum c and d minimum for this c) or the very last (with maximum c and d maximum for this c) record of those matching the where condition. I’d usually strongly prefer no other (than the last/first) records to be selected as there are hundreds thousands of them…

  • 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-01T22:18:08+00:00Added an answer on June 1, 2026 at 10:18 pm

    There’s a potential danger here in how the OP’s query is currently constructed. Run as is, getting the first or last result of a 100K result set is not terribly efficient (unlikely, yes, but the point is, the query places no limit on number of number of rows returned)

    With straight SQL you would never do such a thing; instead you would tack on a LIMIT 1

    In ScalaQuery, LIMIT = take(n), so add take(1) to get a single record returned from the query itself

    val q = (for {
      a <- Parameters[Int]
      b <- Parameters[Int]
      t <- T if t.a == a && t.b == b
      _ <- Query.orderBy(t.c, t.d)
    } yield t) take(1)
    q.firstOption
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query: select column_name, count(column_name) from table group by column_name having
I'm having trouble figuring out how to represent the following JPQL query: SELECT count(e)
I'm having trouble with the following query: SELECT costingjobtimes.TimeStamp, costingdepartment.DeptDesc, costingemployee.Name, costingjobtimes.TimeElapsed FROM costingemployee
I'm having some problems with the following Query: SELECT v.idnum ,v.full_name ,convert(varbinary(max),s.signature) as Sig
I'm having an odd problem with the following query, it works all correct, the
I am having following normal query inside my stored procedure Select DISTINCT UI.UserId,UI.UserName, UI.FullName
I'm having trouble trying to optimize the following query for sql server 2005. Does
I am having problems with the following query in Castle ActiveRecord 2.12: var q
I'm trying to run the following query, and I'm having trouble with the wildcard.
I am having trouble with the following MYSQL query and are hoping that there

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.