SQL Join 返回空集
我的 SQL 连接遇到问题。我想在特定的 ID 号和特定的时间范围内连接两个表,但我只是不断返回一个空集。我想要得到的是两个表之间 ID 号的匹配,并按时间(也称为“术语”)对其进行过滤。我相信 Term 位于 ProcInfo 表上。关于我做错了什么有什么想法吗?
SELECT*
FROM tblPernfo INNER JOIN tblProcInfo ON tblProcInfo.eID=tblPernfo.eID
WHERE Term In ('1st Sum 2010')
ORDER BY Term;
I'm having problems with my SQL Join. I want to join two tables on a specific ID number and during a specific time frame, but I just keep getting an empty set returned. What I want to get is a match between both tables on the ID numbers, and also filter it by time, also called "Term". Term is on the ProcInfo table I believe. Any ideas on what I'm doing wrong?
SELECT*
FROM tblPernfo INNER JOIN tblProcInfo ON tblProcInfo.eID=tblPernfo.eID
WHERE Term In ('1st Sum 2010')
ORDER BY Term;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,
使用 select * 是非常糟糕的做法。它会导致性能问题。
你为什么使用IN? = 应该可以。
现在来了解为什么没有返回记录。这是一个简单的数据集,因此只有几种可能性。首先,tblProcInfo 中没有与 tblPernfo 中的记录匹配的记录。您可以通过运行不带 where 子句的语句来确认或排除这种可能性。
如果它返回记录,则 where 子句是问题,如果它不返回记录,则问题是 join in。接下来运行此(或替换 tblProcInfo idf,它是包含 Term 列的表:
如果返回数据并且第一个查询返回记录,那么剩下的唯一可能性是第二个表中没有与第一个表匹配的记录具体值。
First
it is very poor practice to use select *. It causes performance problems.
Why are you using IN? = should work.
Now to get to why no records are returned. This is a simple dataset, so there are only a coupl eof possibilities. First is that there are no records in tblProcInfo that match to records in tblPernfo. You can confirm or exclude this possibility by running the statement without the where clause.
If it returns records, the where clause is the issue, if it does not the join ins the issue. Next run this ( or substitute tblProcInfo idf that is the table that contains the Term column:
If that returns data and the first query returned records then the only possibility left is that there are no records in the second table that match the first table for this specific value.