简体   繁体   中英

Create a Table from a SQL Query with Hibernate

I have 3 tables that I want to join in a single table collaborator with this Sql query :

select * from (
select user.id, Project.id, Task.id
inner join Project on user.join_key = Project.join_key
inner join  Task  on task.join_key = = Project.join_key
) collaborator

And I can't seem to find How to. I can use this also :

CREATE TABLE Collaborator AS
SELECT user.id, Project.id, Task.id
FROM Project p, Task t, User u
inner join Project on user.join_key = Project.join_key
inner join  Task  on task.join_key = = Project.join_key.

Any help would be appreciated. Thanks

First create the table

Collaborator

CREATE TABLE `Collaborator` (
  `USER_id` int(11),
 `PROJECT_id` int(11),
 `TASK_id` int(11)
) ENGINE=InnoDB

And then excecute the insert

INSERT INTO Collaborator 
SELECT user.id, Project.id, Task.id
FROM Project p, Task t, User u
inner join Project on user.join_key = Project.join_key
inner join  Task  on task.join_key = = Project.join_key

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM