Hi all,
I want to write a query like follow in hql please help me.There is no way that i can find like self query with many join columns. And i am using hibernate annotation API.
QUERY =====
SELECT DISTINCT s1.id, s1.first_name, s1.salary, s1.Description, s2.Description FROM employee s1 LEFT JOIN employee s2 ON s1.city = s2.city AND s1.salary=s2.salary AND s1.start_date!=s2.start_date WHERE s1.start_date='2009-08-05' ;
TABLE =====
CREATE TABLE Employee( id int, first_name VARCHAR(15), last_name VARCHAR(15), start_date DATE, end_date DATE, salary DECIMAL(8,2), city VARCHAR(10), description VARCHAR(15) );
DATA =====
insert into Employee(id,first_name, last_name, start_date, end_Date, salary, City, Description) values (1,'Jason', 'Martin', '2009-08-04', '2009-08-06', 1234.56, 'Toronto', 'AAA'); insert into Employee(id,first_name, last_name, start_date, end_Date, salary, City, Description) values(2,'Alison', 'Mathews', '2009-08-04', '2009-08-06', 6661.78, 'Vancouver','BBB'); insert into Employee(id,first_name, last_name, start_date, end_Date, salary, City, Description) values(3,'James', 'Smith', '2009-08-04', '2009-08-06', 6544.78, 'Vancouver','CCC');
insert into Employee(id,first_name, last_name, start_date, end_Date, salary, City, Description) values (4,'Jason', 'Martin', '2009-08-05', '2009-08-06', 1234.56, 'Toronto', 'Programmer'); insert into Employee(id,first_name, last_name, start_date, end_Date, salary, City, Description) values(5,'Alison', 'Mathews', '2009-08-05', '2009-08-06', 6661.78, 'Vancouver','Tester'); insert into Employee(id,first_name, last_name, start_date, end_Date, salary, City, Description) values(6,'James', 'Smith', '2009-08-05', '2009-08-06', 6544.78, 'Vancouver','Tester'); insert into Employee(id,first_name, last_name, start_date, end_Date, salary, City, Description) values(7,'Celia', 'Rice', '2009-08-05', '2009-08-06', 2344.78, 'Vancouver','Manager'); insert into Employee(id,first_name, last_name, start_date, end_Date, salary, City, Description) values(8,'Robert', 'Black', '2009-08-05', '2009-08-06', 2334.78, 'Vancouver','Tester'); insert into Employee(id,first_name, last_name, start_date, end_Date, salary, City, Description) values(9,'Linda', 'Green', '2009-08-05', '2009-08-06', 4322.78,'New York', 'Tester'); insert into Employee(id,first_name, last_name, start_date, end_Date, salary, City, Description) values(10,'David', 'Larry', '2009-08-05', '2009-08-06', 7897.78,'New York', 'Manager'); insert into Employee(id,first_name, last_name, start_date, end_Date, salary, City, Description) values(11,'James', 'Cat', '2009-08-05', '2009-08-06', 1232.78,'Vancouver', 'Tester');
Thank you.
|