Question: Count distinct value in HQL.

Ads

 
 
 

Share on Google+Share on Google+

ratna rathor
Count distinct value in HQL.
1 Answer(s)      4 years and 11 months ago
Posted in : Hibernate

How do you count distinct value in HQL?

Ads
View Answers

June 1, 2012 at 7:08 PM


count(distinct fieldName) returns number of distinct value of the table under specified field name.

Example :

package net.roseindia.main;

import net.roseindia.util.HibernateUtil;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class DistinctCountHQL {
    public static void main(String[] args) {
        SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
        Session session = sessionFactory.openSession();
        String countHql = "Select count(distinct salary) FROM Employee emp";

        Query countQuery = session.createQuery(countHql);

        System.out.println("Number of Employee: " + countQuery.list().get(0));
    }
}

Output:

Hibernate: select count(distinct employee0_.salary) as col_0_0_ from employee employee0_
Number of Employee having distinct salary : 3

Description: This example counts the number of employee having distinct salary by using count(distinct salary).


Ads









Related Tutorials/Questions & Answers:
Count distinct value in HQL.
Count distinct value in HQL.  How do you count distinct value in HQL?   count(distinct fieldName) returns number of distinct value... = sessionFactory.openSession(); String countHql = "Select count(distinct salary
Hibernate Criteria Count Distinct Example
Hibernate Criteria Count Distinct Example  I am learning Hibernate... Criteria Count Distinct. Can anyone tell me the best place to learn Hibernate Criteria Count Distinct? Thanks   Here is an example of Hibernate Criteria
Advertisements
Hibernate Criteria Count Distinct
Hibernate Criteria Count Distinct The Hibernate Criteria count distinct is used to count the number of distinct records in a table. Following a way to use... this application it will display message as shown below: select count(distinct
Using Min, Max and Count on HQL.
Using Min, Max and Count on HQL.  How to use Min, Max and Count on HQL
HQL
HQL  What is the HQL in hibernate ? Explain the use of HQL.   Hi Friend, Please visit on this link....... Hibernate Query Language
Column count doesn't match value count at row 1
Column count doesn't match value count at row 1  Column count doesn't match value count at row 1 UPDATE user_profile SET id=[value-1],user_id=[value-2],full_name=[value-3],mobile_phone=[value-4],hide_email_id=[value-5],hide
Hibernate count() Function
Hibernate count() Function In this tutorial you will learn how to use the HQL.... for example : count( [ distinct | all ] object | object.property) count(*); also...("select count(distinct gd.numOfGoodsOrder) from GoodsDealer gd"
java.sql.SQLException: Column count doesn't match value count at row 1 - JSP-Servlet
java.sql.SQLException: Column count doesn't match value count at row 1  Hi I am trying to put my data into database. But I found the error of : java.sql.SQLException: Column count doesn't match value count at row 1 I
Distinct and Limit example in MySQL
Distinct and Limit example in MySQL  Hi, How to use the distinct... of distinct in SQL select distinct(last_name) from email; select distinct(last_name) from email where email_count >100; Here is example of limit in MySQL
how to find [count the number of integers whose value is less than the average value of the integers]
how to find [count the number of integers whose value is less than the average value of the integers]  Construct an algorithm that will prompt... program is to display the average integer value and the count of integers less
convert into hql
convert into hql   String sqlListSurveys= "select distinct s.surveyAutoID, s.surveyTitle, date(s.modifiedOn) modifiedOn, s.createdOn, " + "( CASE s.surveyState WHEN '0' THEN 'Created' WHEN '1' THEN 'Published
SQL SELECT DISTINCT Statement
SQL SELECT DISTINCT Statement       In this example we will show you the usage of Distinct clause with the select statement. The SQL Distinct clause is used with the Select statement
HQL query
HQL query  how to select only password based on username using HQL query from login table where uname and paswrd are two column names
Hibernate Count Query
, they return an aggregate value (such as sum, average, and count) calculated from... of them are self-explanatory. count( [ distinct | all ] object... Hibernate Count Query      
HQL Query
HQL Query  Hibernate query language: How to use a left join in Hibernate query language. Can somebody help with an example. I am getting a unexpected token error in HQL Query tool If I use joins
HQL in hibernate ? Explain the use of HQL.
HQL in hibernate ? Explain the use of HQL.  What is the HQL in hibernate ? Explain the use of HQL.   HQL stands for Hibernate Query...(); Session session = sessionFactory.openSession(); String hql="SELECT
HQL Sample
HQL Sample In this site there are many tutorials and example of HQL. These examples comes with HQL sample code that you can download and run on your computer and learn the HQL by modifying and executing these examples. The HQL Sample
SQL SELECT DISTINCT Statement
SQL SELECT DISTINCT Statement       In this example we will show you the usage of Distinct clause with the select statement. The SQL Distinct clause is used with the Select
HQL order by.
HQL order by.  HQL Order by query giving problem.   Order... into descending order you can follow the following HQL ? String hql="Select emp FROM...(); String hql="Select emp FROM Employee emp ORDER BY name"; Query query
how to convert sql into hql
how to convert sql into hql   StringBuffer questionDataSql = new... distinct q.questionVerbiage, qt.questionType, ") .append("GROUP_CONCAT(distinct ifnull(qo.optionVerbiage,'') order by qo.questionOptionAutoID
HQL group By.
HQL group By.  How to use group by in HQL?   In general...=sessionFactory.openSession(); String hql="Select emp.name FROM Employee emp GROUP BY name"; Query query=session.createQuery(hql); query.setResultTransformer
Hibernate Criteria Distinct
Hibernate Criteria Distinct The Hibernate Criteria Distinct API search and display the distinct result Consider the following SQL SELECT DISTINCT name FROM student WHERE roll_no=2; The above SQL will return the  distinct name
Hibernate Query Language (HQL)
Hibernate Query Language (HQL)  What is Hibernate Query Language (HQL)?   HQL is much like SQL and are case-insensitive, except... and execute it against underlying database if HQL is used in the application. HQL
Hibernate HQL Update
In this section we will discuss HQL update with example
Hibernate delete HQL - Hibernate
Hibernate delete HQL  Hi I am trying hibernate tutorial. But delete HQL tutorial not working properly. It gives null pointer exception. Query class has method executeUpate() & not executeUpdate
What is Hibernate Query Language (HQL)?
What is Hibernate Query Language (HQL)?  Hi, What is Hibernate Query Language (HQL)? thanks
count in hibernate .
count in hibernate .  How to implements count in hibernate
Hibernate-HQL subquery - Hibernate
Hibernate-HQL subquery  Hi, I need to fetch latest 5 records from a table.My query goes here. select * from (select * from STATUS... in HQL which should return list of "Status" type beans.Is it possible?If yes
how I do select from select in hql
'a%' order by globalid ) ) where db_id = 259; this is the sql The below hql doesn't work select RN from ( select rownum RN, DBId from ( select distinct p... link: HQL Select Example
Hibernate criteria Distinct_Root_Entity Example
Hibernate criteria Distinct_Root_Entity Example  How to create Criteria DistinctRootEntity Example in Hibernate? Thanks   Example program of hibernate criteria DistinctRootEntity. Check the tutorial hibernate criteria
HQL update problem
HQL update problem  public void saveGuest(List<Long> listid) throws HibernateException{ SessionFactory sf... table HQL plz help
Tutorials   
Java Spring Hibernate Struts Training Hibernate Envers custom revinfo table Hibernate Envers - REVINFO table doesn't exist How to enable second level cache in Hibernate 5? How to enable second level cache in Hibernate 5? java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based! org.hibernate.validator cannot be resolved error java.lang.ClassNotFoundException: org.hibernate.cache.TimestampsRegion java.lang.ClassNotFoundException: org.hibernate.cache.TimestampsRegion property hibernate.cache.region.factory_class is not given Hibernate example step by step in Eclipse with MySQL How to make Struts Hibernate and Spring Based Login/Registration Application? What is the use of Hibernate Native SQL? What is the use of Hibernate is used? How to integrate Struts and Hibernate in an application? How to create the program in Java for getting the forgotten Password Form? How to write create JPA Many-to-Many Relationship in Java? What is the DAO Layer in any application? What is Spring Struts Hibernate DAO Layer? How to write Example code for CRUD application in hibernate annotation? Where to update the Hibernate tools? Query conversion convert into hql how to convert sql into hql package org.hibernate.util does not exist C3P0 with Hibernate What do you understand by JPA? Hibernate Query Checker Jpa many to many relationship What do you understand by Hibernate in Java? What are criteria Queries in Hibernate? How to use Associations and Joins in Hibernate? Hibernate 4 Example with Eclipse How to learn Hibernate? What is Hibernate Framework? hibernate faq 15/03/14 hibernate 15/03/2014 Hibernate Criteria Wildcard how to add mulitiple projections this is a hibernate question this is a hibernate question this is a hibernate question how to writw connection pool coding Hibernate 4.3 and JPA 2.1 support How to create Hibernate session factory name? Can you provide me Hibernate configuration tutorial? I want to build sessionfactory in hibernate 4. Need help. I want to learn Hibernate tutorial quickly How to create sessionfactory in Hibernate 4.1.1? How to create sessionfactory in Hibernate 4.1? Hibernate 4.3.0.Final get session

Ads

 
Advertisement null

Ads