{"id":219,"date":"2015-01-20T10:02:33","date_gmt":"2015-01-20T07:02:33","guid":{"rendered":"http:\/\/blog.leodev.ru\/?p=219"},"modified":"2016-01-23T18:56:50","modified_gmt":"2016-01-23T15:56:50","slug":"sql-join","status":"publish","type":"post","link":"https:\/\/leodev.ru\/blog\/mysql\/sql-join\/","title":{"rendered":"SQL Join"},"content":{"rendered":"<p><em>\u0423\u0432\u044b \u0440\u0435\u0434\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c, \u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0441\u0440\u0435\u0434\u044b \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0432 \u043f\u043b\u043e\u0442\u043d\u0443\u044e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a \u0431\u043b\u043e\u0433\u0443.<\/em><\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e JOIN.\u00a0\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e Wiki:<\/p>\n<blockquote><p><b>JOIN<\/b>\u00a0\u2014 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u044f\u0437\u044b\u043a\u0430 <a title=\"SQL\" href=\"https:\/\/ru.wikipedia.org\/wiki\/SQL\">SQL<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 <a title=\"\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (\u0421\u0423\u0411\u0414)\" href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9E%D0%BF%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D1%8F_%D1%81%D0%BE%D0%B5%D0%B4%D0%B8%D0%BD%D0%B5%D0%BD%D0%B8%D1%8F_(%D0%A1%D0%A3%D0%91%D0%94)\">\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/a> <a title=\"\u0420\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0430\u043b\u0433\u0435\u0431\u0440\u0430\" href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A0%D0%B5%D0%BB%D1%8F%D1%86%D0%B8%D0%BE%D0%BD%D0%BD%D0%B0%D1%8F_%D0%B0%D0%BB%D0%B3%D0%B5%D0%B1%D1%80%D0%B0\">\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0430\u043b\u0433\u0435\u0431\u0440\u044b<\/a>. \u0412\u0445\u043e\u0434\u0438\u0442 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b <a class=\"new\" title=\"FROM (SQL) (\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442)\" href=\"https:\/\/ru.wikipedia.org\/w\/index.php?title=FROM_(SQL)&amp;action=edit&amp;redlink=1\">FROM<\/a> \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 <a title=\"Select (SQL)\" href=\"https:\/\/ru.wikipedia.org\/wiki\/Select_(SQL)\">SELECT<\/a>, <a title=\"Update (SQL)\" href=\"https:\/\/ru.wikipedia.org\/wiki\/Update_(SQL)\">UPDATE<\/a> \u0438\u043b\u0438 <a title=\"Delete (SQL)\" href=\"https:\/\/ru.wikipedia.org\/wiki\/Delete_(SQL)\">DELETE<\/a>.<\/p>\n<p>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043e\u0434\u0438\u043d \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440. \u041e\u0442\u043b\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p><\/blockquote>\n<ul>\n<li>\n<blockquote><p>\u0432 \u0441\u0445\u0435\u043c\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b-\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u0445\u043e\u0434\u044f\u0442 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u043e\u0431\u0435\u0438\u0445 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 (\u0442\u0430\u0431\u043b\u0438\u0446-\u043e\u043f\u0435\u0440\u0430\u043d\u0434\u043e\u0432), \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0445\u0435\u043c\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u00ab\u0441\u0446\u0435\u043f\u043b\u0435\u043d\u0438\u0435\u043c\u00bb \u0441\u0445\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u043d\u0434\u043e\u0432;<\/p><\/blockquote>\n<\/li>\n<li>\n<blockquote><p>\u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b-\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u00ab\u0441\u0446\u0435\u043f\u043b\u0435\u043d\u0438\u0435\u043c\u00bb \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b-\u043e\u043f\u0435\u0440\u0430\u043d\u0434\u0430 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0432\u0442\u043e\u0440\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b-\u043e\u043f\u0435\u0440\u0430\u043d\u0434\u0430.<\/p><\/blockquote>\n<\/li>\n<\/ul>\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u00a0CROSS JOIN \u0441\u0430\u043c\u0438 \u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u044f \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043e\u0431\u044a\u0435\u043c\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0435 \u0440\u0435\u043d\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0411\u0414.<!--more--><\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c 2 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/p>\n<table>\n<tbody>\n<tr>\n<td colspan=\"2\" width=\"45\">T1<\/td>\n<td width=\"7\"><\/td>\n<td colspan=\"2\">T2<\/td>\n<\/tr>\n<tr>\n<td><strong><span style=\"text-decoration: underline;\">k1<\/span><\/strong><\/td>\n<td width=\"22\"><strong>d1<\/strong><\/td>\n<td width=\"7\"><\/td>\n<td><strong><span style=\"text-decoration: underline;\">k1<\/span><\/strong><\/td>\n<td><strong>d2<\/strong><\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td width=\"22\">1<\/td>\n<td width=\"7\"><\/td>\n<td>1<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td width=\"22\">2<\/td>\n<td width=\"7\"><\/td>\n<td>2<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td width=\"22\">3<\/td>\n<td width=\"7\"><\/td>\n<td>5<\/td>\n<td>50<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td width=\"22\">4<\/td>\n<td width=\"7\"><\/td>\n<td>6<\/td>\n<td>60<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>CROSS JOIN<\/h2>\n<p>\u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c &#171;\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439&#187; SELECT<\/p>\n<pre class=\"lang:mysql decode:true\">SELECT d1, d2\r\nFROM T1, T2\r\nWHERE k1 = k2<\/pre>\n<blockquote><p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442(\u0433\u0434\u0435 k1 = k2): <\/strong><\/p>\n<p>1:10<\/p>\n<p>2:20<\/p><\/blockquote>\n<p>\u0412\u0440\u043e\u0434\u0435 \u0432\u0441\u0435 \u043e\u043a \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0447\u0442\u043e \u043f\u0440\u043e\u0441\u0438\u043b\u0438 \u0442\u043e \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438.\u00a0\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u043f\u043e\u0434 &#171;\u043a\u043e\u043f\u043e\u0442&#187;.<\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:mysql decode:true\">SELECT d1, d2\r\nFROM T1, T2<\/pre>\n<p>\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430 \u0448\u0438\u0440\u043c\u043e\u0439 \u0431\u0443\u0434\u0435\u0442\u00a0\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c<\/p>\n<table>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>50<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>60<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>50<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>60<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>50<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>60<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>50<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">2<\/td>\n<td style=\"text-align: center;\">60<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0438\u0447\u0435\u0433\u043e \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e\u0433\u043e, \u043d\u043e \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u043f\u0430\u0440\u0443 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435?<\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0431\u0443\u0434\u0435\u0442 4 \u0431\u0438\u043b\u043b\u0438\u043e\u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 WHERE \u043d\u0430\u0447\u043d\u0435\u0442 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437 16 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e 2<\/p>\n<p>\u0418\u0437\u0431\u0435\u0433\u0430\u0435\u0442\u0441\u044f CROSS JION \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<h2>INNER JOIN<\/h2>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <i>\u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/i> INNER JOIN \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0434\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0442\u0430\u0431\u043b\u0438\u0446 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043d\u0435\u0432\u0430\u0436\u0435\u043d, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u044b\u043c.<\/p>\n<pre class=\"lang:default decode:true\">SELECT d1,d2\r\nFROM T1\r\nINNER JOIN T2\r\nON T1.k1=T2.k2<\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>d1<\/strong><\/td>\n<td><strong>d2<\/strong><\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>20<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>LEFT\u00a0JOIN<\/h2>\n<p>LEFT JOIN \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0432\u0437\u044f\u0442\u044c \u0438\u0437 \u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043a \u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432\u0441\u0435 \u0433\u0434\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/p>\n<pre class=\"lang:default decode:true\">SELECT d1,d2\r\nFROM T1\r\nLEFT JOIN T2\r\nON T1.k1=T2.k2<\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>d1<\/strong><\/td>\n<td><strong>d2<\/strong><\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Null<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Null<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h2>RIGHT JOIN<\/h2>\n<p>RIGHT\u00a0JOIN \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d LEFT.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a\u00a0\u043c\u044b\u00a0\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043e\u0442 \u043f\u0440\u0430\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b , \u0430 \u0432 \u043d\u0435\u0439 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043b\u044e\u0447\u0430 3 \u0438 4 \u0442\u043e \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c 50 \u0438 60 \u0441\u043f\u0440\u0430\u0432\u0430 \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u0443\u044e\u00a0\u0432\u044b\u0431\u043e\u0440\u043a\u0443. \u0410 \u0441\u043b\u0435\u0432\u0430 \u0431\u0443\u0434\u0435\u0442 Null \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u043a\u043b\u044e\u0447\u0430 5 \u0438 6 \u043d\u0435\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 1<\/p>\n<pre class=\"lang:default decode:true\">SELECT d1,d2\r\nFROM T1\r\nRIGHT JOIN T2\r\nON T1.k1=T2.k2<\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>d1<\/strong><\/td>\n<td><strong>d2<\/strong><\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>Null<\/td>\n<td>50<\/td>\n<\/tr>\n<tr>\n<td>Null<\/td>\n<td>60<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u00a0FULL\u00a0JOIN (\u043d\u0435 \u0432\u0441\u0435 \u0411\u0414 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442)<\/h2>\n<p>FULL\u00a0JOIN \u0441\u043b\u0438\u0432\u0430\u0435\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0433\u0434\u0435 \u043a\u043b\u044e\u0447\u0438\u00a0\u0440\u0430\u0432\u043d\u044b \u043b\u0438\u0431\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u044c\u0430\u0431\u043b\u0438\u0446.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a\u00a0\u043c\u044b\u00a0\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043e\u0442 \u043f\u0440\u0430\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b , \u0430 \u0432 \u043d\u0435\u0439 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043b\u044e\u0447\u0430 3 \u0438 4 \u0442\u043e \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c 50 \u0438 60 \u0441\u043f\u0440\u0430\u0432\u0430 \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u0443\u044e\u00a0\u0432\u044b\u0431\u043e\u0440\u043a\u0443. \u0410 \u0441\u043b\u0435\u0432\u0430 \u0431\u0443\u0434\u0435\u0442 Null \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u043a\u043b\u044e\u0447\u0430 5 \u0438 6 \u043d\u0435\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 1<\/p>\n<pre class=\"lang:default decode:true\">SELECT d1,d2\r\nFROM T1\r\nFULL JOIN T2\r\nON T1.k1=T2.k2<\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>d1<\/strong><\/td>\n<td><strong>d2<\/strong><\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Null<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Null<\/td>\n<\/tr>\n<tr>\n<td>Null<\/td>\n<td>50<\/td>\n<\/tr>\n<tr>\n<td>Null<\/td>\n<td>60<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><em>\u00a0\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f FULL Join \u043d\u0435 \u0432\u0441\u0435\u043c\u0438 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 UNION<\/em><\/p>\n<h2>\u00a0UNION<\/h2>\n<p>UNION \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0431\u0449\u0435\u0433\u043e \u0441 JOIN.\u00a0UNION \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435. \u0422\u043e \u0435\u0441\u0442\u044c \u0432\u0437\u044f\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 1 \u0438 \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 2<\/p>\n<pre class=\"lang:default decode:true\">SELECT d1,d2\r\nFROM T1\r\nLEFT JOIN T2\r\nON T1.k1=T2.k2\r\nUNION ALL\r\nSELECT d1,d2\r\nFROM T1\r\nRIGHT JOIN T2\r\nON T1.k1=T2.k2\r\nWHERE d1 is Null\r\n<\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>d1<\/strong><\/td>\n<td><strong>d2<\/strong><\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Null<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Null<\/td>\n<\/tr>\n<tr>\n<td>Null<\/td>\n<td>50<\/td>\n<\/tr>\n<tr>\n<td>Null<\/td>\n<td>60<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043d\u0430<\/p>\n<pre class=\"lang:default decode:true\">WHERE d1 is Null<\/pre>\n<p><span style=\"color: #ff6600;\">\u00a0\u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0430\u0437\u0430\u0445 \u0441\u0432\u043e\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 Null \u0431\u0443\u0434\u044c\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0439.<\/span><\/p>\n<p>\u0423 \u043a\u043e\u0433\u043e \u0432\u0441\u0435 \u0435\u0449\u0435 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043a \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0443 \u0432\u0438\u0434\u0435\u043e\u00a0Vladimira Mozhenkova<\/p>\n<p><iframe loading=\"lazy\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/EHvzvwAv7RU?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0423\u0432\u044b \u0440\u0435\u0434\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c, \u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0441\u0440\u0435\u0434\u044b \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0432 \u043f\u043b\u043e\u0442\u043d\u0443\u044e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a \u0431\u043b\u043e\u0433\u0443. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e JOIN.\u00a0\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e Wiki: JOIN\u00a0\u2014 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u044f\u0437\u044b\u043a\u0430 SQL, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0430\u043b\u0433\u0435\u0431\u0440\u044b. \u0412\u0445\u043e\u0434\u0438\u0442 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b FROM \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 SELECT, UPDATE \u0438\u043b\u0438 DELETE. \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 &hellip; <a href=\"https:\/\/leodev.ru\/blog\/mysql\/sql-join\/\" class=\"more-link\">\u0427\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435<span class=\"screen-reader-text\"> \u00abSQL Join\u00bb<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":222,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[106],"tags":[59,48,58],"class_list":["post-219","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","tag-join","tag-mysql","tag-sql"],"_links":{"self":[{"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":7,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":227,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/posts\/219\/revisions\/227"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/media\/222"}],"wp:attachment":[{"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}