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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:41:45+00:00 2026-06-05T20:41:45+00:00

Using ORMLite, I want to count the number of database items that fit certain

  • 0

Using ORMLite, I want to count the number of database items that fit certain criteria. A simplified version of my database is as follows:

Employee Table:
 employeeId
 departmentId

Department Table:
 departmentId

Salary Table:
 employeeId
 payGrade

Suppose I want to count the number of employees from a subset of departments that are at certain pay grade. When I try something like the following, I get an exception reporting that only one select column is allowed.

salaryQB.selectColumns(salaryQB.EMPLOYEE_ID);
salaryQB.where().eq(salaryQB.PAY_GRADE, 12);
employeeQB.where.in(Employee.DEPARTMENT_ID, departmentList)
      .and().in(employeeQB.EMPLOYEE_ID, salaryQB);

employeeQB.setCountOf(true);
count = dao.countOf(employeeQB.prepare());

But code like this returns the following error:

RuntimeException (java.sql.SQLException: Inner query must have only 1
select column specified instead of 2)

Is there any way to do this short of writing a raw SQL 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-05T20:41:48+00:00Added an answer on June 5, 2026 at 8:41 pm

    Hrm. I can’t see any problems with your code @Jeff. I’ve improved the exception message in ORMLite to show the actual field names for the future but that won’t help you right now:

    Inner query must have only 1 select column specified instead of 2: [id, foreign]

    The message is [obviously] trying to tell you that you have specified more than one selectColumns(...) in the salaryQB inner QueryBuilder. But you seem to be only selecting one column here:

    salaryQB.selectColumns(salaryQB.EMPLOYEE_ID);
    

    I don’t see where the salaryQB is defined but maybe there is some more code somewhere else that also is using selectColumns? I’ve tried to reproduce the error in the testInnerCountOf() method towards the bottom of the QueryBuilderTest unit test but it seems to work fine.

    If you can reproduce this in a unit test or if you can see how my unit test differs from your config then let me know.

    Edit:

    As of version 4.22 (from 9/2012), ORMLite now supports simple JOIN statements. So your query can be simplified to:

    salaryQB.where().eq(salaryQB.PAY_GRADE, 12);
    employeeQB.join(salaryQB);
    employeeQB.where().in(Employee.DEPARTMENT_ID, departmentList);
    employeeQB.setCountOf(true);
    count = dao.countOf(employeeQB.prepare());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ormlite for database interaction in java. Works fine. Now I want to
I am programming an Android app and using ormLite for the database. I want
Using Nunit, I want to be able to write a test fixture that will
Hello i am using ORMLite 4.33. I have an entity class that gives me
I'm using ORMLite & SQLite as my database, and I'm working on a android
quick question about using ORMLite. I am trying to make sure that my implementation
I'm using ormlite for my android-app. But now i have a problem. I have
I have just started reading about ORMLite since I am interested in using it
I have a class which I want to persist with OrmLite and it stores
Using WPF/PRISM I want to log my messages through ILoggerFacade to my GUI (A

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.