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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:04:40+00:00 2026-05-20T02:04:40+00:00

I have multiple tables : vote Question Answer Each of these tables have an

  • 0

I have multiple tables :

  1. vote
  2. Question
  3. Answer

Each of these tables have an authorId field.

I want to output this in an sql query :

MemberId1 . (Nbr of votes + Nbr of Question + Nbr of Answer )

MemberId2 . (Nbr of votes + Nbr of Question + Nbr of Answer )

MemberId3 . (Nbr of votes + Nbr of Question + Nbr of Answer )

How can I do this query with Hibernate criterias ?

In plain SQL I think it would be like this :

select sum(val) from (

select count(*) val from a

union all

select count(*) val from b

union all

select count(*) val from c

union all

select count(*) val from d )
  • 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-20T02:04:41+00:00Added an answer on May 20, 2026 at 2:04 am

    This should do the trick, provided that you have mapped the one-to-many relationships between authors and the three entities in Author :

    Criteria criteria = session.createCriteria(Author.class, "author");
    criteria.createAlias("author.votes", "v", Criteria.LEFT_JOIN);
    criteria.createAlias("author.questions", "q", Criteria.LEFT_JOIN);
    criteria.createAlias("author.answers", "a", Criteria.LEFT_JOIN);
    criteria.setProjection(
        Projections.projectionList().add(Projections.groupProperty("author.id"))
                                    .add(Projections.countDistinct("v.id"))
                                    .add(Projections.countDistinct("q.id"))
                                    .add(Projections.countDistinct("a.id")));
    

    EDIT :

    But since the query is not dynamic, you should probably prefer HQL, which would allow you to write your query even if there’s no mapping of the relationships in Author :

    select author.id, count(distinct(v.id)), count(distinct(q.id)), count(distinct(a.id))
    from Author author, Vote v, Question q, Answer a
    where v.author.id = author.id
    and   q.author.id = author.id
    and   a.author.id = author.id
    group by author.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database with multiple tables, each of which have the same
I have a dynamic search query with join multiple tables, for showing sum and
tableOk so what I want to do is the following I have multiple tables
I have multiple tables (one for each day) that all have the same structure:
I have multiple tables with information about tube videos. I need to join these
I have multiple html tables. Each table has the same number of columns but
I have multiple tables that are randomly generated. I only want the first row
I have multiple tables in a MySQL database. Lets say they look like this:
I have created Windows Application. In this, I have multiple tables in dataset, now
I have multiple tables on my website. They are each styled by the following

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.