-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: LEFT Joins one table with itself
PostPosted: Wed Aug 05, 2009 9:25 am 
Newbie

Joined: Wed Aug 05, 2009 9:11 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.