0

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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

the only thing I would suggest is to explicitly identify columns on insert the lazy style like this can lead to issues when/if columns change on the table or in the select. INSERT INTO Collaborator (User_id, Project_id, Task_id)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.