Created
February 11, 2020 18:22
-
-
Save supervoron1/0594c46d30008b0864b0e222fbb0d826 to your computer and use it in GitHub Desktop.
SQL Join as many as you like
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Select <column list> | |
From T1 | |
Join T2 on T1.key = T2.key | |
Join T3 in T2.key = T3.key | |
--------------------------------- | |
CREATE TABLE `authors` ( | |
`id` int(11) NOT NULL, | |
`title` varchar(32) NOT NULL | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; | |
CREATE TABLE `status` ( | |
`id` int(11) NOT NULL, | |
`title` varchar(32) NOT NULL | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; | |
CREATE TABLE `tasks` ( | |
`id` int(11) NOT NULL, | |
`title` varchar(64) NOT NULL, | |
`author_id` int(11) NOT NULL, | |
`status_id` int(11) NOT NULL | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; | |
-------------------------- *** -------------------------- | |
SELECT tasks.id, tasks.title, authors.title AS author_name, status.title AS status_name | |
FROM tasks | |
JOIN authors ON tasks.author_id = authors.id | |
JOIN status ON tasks.status_id = status.id | |
В результате объединение 3 таблиц по `author_id` и `status_id` | |
--------------------------- *** ----------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment