SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE `improvement_suggestions` ( `id` int(10) unsigned NOT NULL, `author_id` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB; CREATE TABLE `improvement_suggestion_comments` ( `id` int(10) unsigned NOT NULL, `suggestion_id` int(10) unsigned NOT NULL, `created_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB; CREATE TABLE `improvement_suggestions_divisions_to_users` ( `user_id` int(10) unsigned NOT NULL ) ENGINE=InnoDB; INSERT INTO `improvement_suggestions` (id,author_id) VALUES (39,NULL), (42,NULL), (303,106), (304,106), (306,106), (308,106), (317,107), (318,107), (319,107), (320,107), (321,107), (322,107), (25,190), (24,262), (327,369), (328,369), (329,369), (33,450), (34,450), (35,450), (36,450), (38,507), (40,507), (45,553), (37,577), (22,778), (41,792), (46,801), (26,828), (95,828), (122,828), (123,828), (43,983), (44,983), (112,1032), (113,1032), (114,1032), (84,1054), (110,1054), (62,1090), (66,1090), (87,1090), (313,1090), (111,1091), (82,1099), (83,1099), (323,1099), (324,1099), (67,1104), (102,1104), (314,1104), (85,1158), (108,1158), (305,1158), (311,1158), (325,1158), (86,1159), (107,1165), (316,1181), (106,1201), (120,1280), (121,1281), (307,1304), (310,1304), (309,1307), (312,1330), (315,1375), (326,1409); INSERT INTO `improvement_suggestion_comments` (id,suggestion_id,created_at) VALUES (3,22,'2024-04-09 13:38:47'), (4,22,'2024-04-09 13:51:43'), (6,26,'2024-04-25 17:14:28'), (11,40,'2024-05-31 17:57:15'), (14,62,'2024-06-17 10:45:20'), (21,86,'2024-06-19 14:14:24'), (22,86,'2024-06-19 14:15:11'), (37,62,'2024-07-18 13:40:58'), (41,87,'2024-07-19 10:12:18'), (42,87,'2024-07-19 10:12:21'), (43,305,'2024-07-31 07:25:59'), (44,305,'2024-08-01 11:28:36'), (45,305,'2024-08-06 07:17:26'), (46,108,'2024-08-14 13:02:33'), (47,111,'2024-08-23 10:00:31'), (48,111,'2024-09-03 08:51:39'); INSERT INTO `improvement_suggestions_divisions_to_users` (user_id) VALUES (1), (42), (103), (106), (152), (155), (189), (190), (219), (262), (407), (455), (551), (553), (565), (577), (587), (616), (635), (638), (662), (704), (722), (731), (757), (774), (778), (804), (827), (828), (833), (875), (902), (929), (934), (937), (945), (946), (957), (1000), (1008), (1015), (1021), (1023), (1036), (1046), (1047), (1048), (1049), (1051), (1052), (1053), (1054), (1058), (1060), (1063), (1064), (1065), (1067), (1068), (1069), (1081), (1083), (1087), (1089), (1090), (1091), (1092), (1096), (1097), (1099), (1100), (1103), (1104), (1107), (1108), (1109), (1111), (1112), (1113), (1114), (1115), (1116), (1117), (1119), (1121), (1123), (1124), (1126), (1129), (1130), (1137), (1138), (1143), (1144), (1146), (1152), (1156), (1157), (1158), (1159), (1165), (1166), (1167), (1177), (1179), (1180), (1181), (1182), (1183), (1184), (1187), (1188), (1202), (1203), (1210), (1211), (1218), (1224), (1225), (1226), (1227), (1228), (1229), (1230), (1237), (1238), (1242), (1243), (1244), (1245), (1246), (1247), (1249), (1250), (1255), (1256), (1258), (1259), (1261), (1267), (1268), (1269), (1273), (1275), (1278), (1279), (1280), (1281), (1287), (1288), (1289), (1292), (1293), (1301), (1302), (1303), (1304), (1306), (1307), (1309), (1310), (1312), (1315), (1316), (1317), (1318), (1320), (1322), (1323), (1327), (1330), (1333), (1338), (1339), (1341), (1342), (1343), (1350), (1352), (1353), (1355), (1357), (1358), (1361), (1362), (1364), (1365), (1366), (1367), (1368), (1369), (1370), (1371), (1375), (1377), (1378), (1379), (1380), (1381), (1382), (1383), (1384), (1389), (1391), (1392), (1394), (1395), (1396), (1397), (1398), (1401), (1404), (1405), (1406), (1407), (1409), (1410), (1413), (1414), (1415); SELECT `improvement_suggestions`.`id`, `improvement_suggestions`.`author_id`, `author_divisions`.`user_id` AS `user_id`, `last_comments`.`last_comment_id`, IF( `improvement_suggestions`.`author_id` = 1158 AND `author_divisions`.`user_id` IS NULL, 'В user_id ДОЛЖНО БЫТЬ 1158', '' ) AS error FROM `improvement_suggestions` LEFT JOIN ( SELECT `improvement_suggestion_comments`.`id` AS `last_comment_id`, `improvement_suggestion_comments`.`suggestion_id` AS `last_comment_suggestion_id` FROM `improvement_suggestion_comments` INNER JOIN ( SELECT `improvement_suggestion_comments`.`suggestion_id`, MAX(improvement_suggestion_comments.created_at) AS created_at FROM `improvement_suggestion_comments` GROUP BY `improvement_suggestion_comments`.`suggestion_id` ) AS `max` ON `improvement_suggestion_comments`.`suggestion_id` = `max`.`suggestion_id` AND `improvement_suggestion_comments`.`created_at` = `max`.`created_at` ) AS `last_comments` ON `last_comments`.`last_comment_suggestion_id` = `improvement_suggestions`.`id` LEFT JOIN ( SELECT `improvement_suggestions_divisions_to_users`.`user_id` FROM `improvement_suggestions_divisions_to_users` GROUP BY `improvement_suggestions_divisions_to_users`.`user_id` ) AS `author_divisions` ON `author_divisions`.`user_id` = `improvement_suggestions`.`author_id` ORDER BY `improvement_suggestions`.`id` DESC

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear