как узнать, какие строки извлекаются из нескольких таблиц в сетку, с каким именем таблицы - PullRequest
0 голосов
/ 09 мая 2019

У меня запрос к получению дубликатов записей и объединению их всех для привязки к сетке с успехом.теперь я просто хочу знать, во время удаления выбранных записей из какой таблицы.Возможно ли это с несколькими строками таблиц.

str += "(SELECT ";
                str += "s.Id, s.EmailAddress As ColumnValue,";
                str += "(SELECT Name FROM tbl_User_master ";
                str += "WHERE Id = s.user_id) AS CreatedBy,";
                str += "s.SubscriptionDateTime As CreatedDate,d.Count ";
                str += "FROM ";
                str += "(SELECT EmailAddress, COUNT(*) as Count ";
                str += "FROM tbl_Subscribers ";
                str += "WHERE user_id = '" + int.Parse(CommonLogic.GetSessionValue("user_id").ToString()) + "' ";
                str += "GROUP BY EmailAddress ";
                str += "HAVING COUNT(*) > 1) AS d ";
                str += "INNER JOIN ";
                str += "tbl_Subscribers s ON s.EmailAddress = d.EmailAddress)";
                str += " UNION ALL ";
                str += "(SELECT ";
                str += "f.Id,f.EmailAddress As ColumnValue,";
                str += "(SELECT Name FROM tbl_User_master WHERE Id = f.user_id) AS CreatedBy,";
                str += "f.CreatedDate As CreatedDate,d.Count ";
                str += "FROM ";
                str += "(SELECT EmailAddress, COUNT(*) AS Count ";
                str += "FROM tbl_From_master ";
                str += "WHERE user_id = '" + int.Parse(CommonLogic.GetSessionValue("user_id").ToString()) + "' ";
                str += "GROUP BY EmailAddress ";
                str += "HAVING COUNT(*) > 1) AS d ";
                str += "INNER JOIN ";
                str += "tbl_From_master f ON f.EmailAddress = d.EmailAddress)";
                str += " UNION ALL ";
                str += "(SELECT ";
                str += "c.Id,c.CategoryName As ColumnValue,(SELECT Name FROM tbl_User_master WHERE Id = c.user_id) As CreatedBy,NULL As CreatedDate,d.Count ";
                str += "FROM (";
                str += "SELECT CategoryName, COUNT(*) as Count ";
                str += "FROM tbl_Categories WHERE user_id='" + int.Parse(CommonLogic.GetSessionValue("user_id").ToString()) + "' ";
                str += "GROUP BY CategoryName ";
                str += "HAVING COUNT(*) > 1";
                str += ") AS d ";
                str += "INNER JOIN tbl_Categories c ON c.CategoryName = d.CategoryName)";
                str += " UNION ALL ";
                str += "(SELECT ";
                str += "t.Id,t.CategoryName As ColumnValue,(SELECT Name FROM tbl_User_master WHERE Id = t.user_id) As CreatedBy,NULL As CreatedDate,d.Count ";
                str += "FROM (";
                str += "SELECT CategoryName, COUNT(*) as Count ";
                str += "FROM tbl_Template_Categories WHERE user_id='" + int.Parse(CommonLogic.GetSessionValue("user_id").ToString()) + "' ";
                str += "GROUP BY CategoryName ";
                str += "HAVING COUNT(*) > 1";
                str += ") AS d ";
                str += "INNER JOIN tbl_Template_Categories t ON t.CategoryName = d.CategoryName)";
                str += " UNION ALL ";
                str += "(SELECT ";
                str += "t.Id,t.TemplateName As ColumnValue,(SELECT Name FROM tbl_User_master WHERE Id = t.user_id) As CreatedBy,t.Created_date As CreatedDate,d.Count ";
                str += "FROM (";
                str += "SELECT TemplateName, COUNT(*) as Count ";
                str += "FROM tbl_Template_master WHERE user_id='" + int.Parse(CommonLogic.GetSessionValue("user_id").ToString()) + "' ";
                str += "GROUP BY TemplateName ";
                str += "HAVING COUNT(*) > 1";
                str += ") AS d";
                str += " INNER JOIN tbl_Template_master t ON t.TemplateName = d.TemplateName)";

, как бы вид сетки связывал все строки с уникальным идентификатором, но как узнать номер данной таблицы.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...