【发布时间】:2023-03-30 00:06:02
【问题描述】:
我编写了一个 SQL 语句,其中这些特定列来自一个表,它与另一个表连接,主键 ReportID 用作两个表之间的链接。 I am using NOT IN to accurately display the reports of a company, but I get no output when a company is selected.查询中是否有我必须重新排列的地方?
valsql1 = "SELECT DISTINCT c.ReportID, c.COMPANYID, rl.REPORTNAME
FROM CompanyReportListTable c
right join ReportList rl on c.reportid = rl.ReportID
WHERE c.reportid NOT IN(Select rl.ReportID FROM ReportList rl)
and rl.ReportVisible = 1
and CompanyID = " & DropDownList1.SelectedValue
【问题讨论】:
-
MySQL和SQL-Server不是一回事,你实际用的是哪个?
-
在暴露于 sql 注入之前,您应该阅读、理解并开始使用参数化查询。
-
您的
not in选择您加入的表中的所有记录,不包括其中的所有记录。 -
@RonRonmonsterererAnkrah - 它将禁用数据库中的所有约束并删除数据库中的所有表。开始使用参数化查询来避免像上面那样的 sql 注入。
-
Prdp 试图解释 SQL 注入攻击可能出现的问题。这些都与您提出的问题无关。有很多关于 SQL 注入的信息供您追踪。
标签: sql-server join notin