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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:19:25+00:00 2026-05-26T00:19:25+00:00

For optimization purpose, I want to fetch first N results in a subquery (I’m

  • 0

For optimization purpose, I want to fetch first N results in a subquery (I’m getting first N ID values) and in the main query fetch full rows for the ID values in the subquery and order them. What I have now is

// This just adds params to the subquery
Expression managedEmp = generateExpression(p_upravljackaFilter);
ReportQuery subQuery = new ReportQuery(CustomDocument.class,
    managedEmp);

subQuery.addAttribute("m_id");

Expression exp = new ExpressionBuilder().get("m_id").in(subQuery);
ReadAllQuery testQuery = new ReadAllQuery(CustomDocument.class,
    exp);
testQuery.addAscendingOrdering("m_creationDate");

List documentList = (List)getTopLinkTemplate().executeQuery(testQuery, true);

What I’m trying so far is using a user defined function, like this:

ExpressionOperator fetchFirst = new ExpressionOperator();
fetchFirst.setSelector(1);
Vector s = new Vector();
s.addElement("FETCH FIRST 5 ROWS ONLY");
fetchFirst.printsAs(s);
fetchFirst.bePostfix();
fetchFirst.setNodeClass(FunctionExpression.class);
ExpressionOperator.initializeOperators();
ExpressionOperator.addOperator(fetchFirst);
expression = expression.and(builder.get("m_datumKreiranja").getFunction(fetchFirst);

This is literally where I stopped so this won’t work but it can show you which way I’m heading. Is something like this even possible? I’m using Java 1.4 and toplink 10g.

  • 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-05-26T00:19:26+00:00Added an answer on May 26, 2026 at 12:19 am

    Really simple, just insert into second line:

    managedEmp = managedEmp.postfixSQL("FETCH FIRST 5 ROWS ONLY");
    

    My mistake was in the fact that I tried it like this:

    managedEmp.postfixSQL(“FETCH FIRST 5 ROWS ONLY”);

    because I didn’t read what postfixSQL does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When doing query optimization, the SHOW STATUS query returns values that are easy to
I'm coding a Vec3 class, and for optimization purpose, I make it with no
I have overloaded SQL Server, and I want to make some optimization. For that
Optimization of PHP code via runtime benchmarking is straight forward. Keep track of $start
What optimization techniques do you use on extremely large databases? If our estimations are
We have several different optimization algorithms that produce a different result for each run.
Search Engine Optimization (SEO) seems to be a topic I'm running into more and
Im on an optimization crusade for one of my sites, trying to cut down
I am interested in optimization at runtime by a VM and at compile-time. I
As an optimization, I decided to put an object I frequently need - an

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.