简体   繁体   English

SQL Join 返回空集

[英]SQL Join returns empty set

I'm having problems with my SQL Join.我的 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.我想在特定的 ID 号和特定的时间范围内加入两个表,但我只是不断返回一个空集。 What I want to get is a match between both tables on the ID numbers, and also filter it by time, also called "Term".我想要得到的是两个表之间的ID号匹配,并且还按时间过滤它,也称为“术语”。 Term is on the ProcInfo table I believe.我相信术语在 ProcInfo 表上。 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;

First第一的

SELECT (specify columns here)     
FROM tblPernfo 
INNER JOIN tblProcInfo ON tblProcInfo.eID=tblPernfo.eID     
WHERE Term In ('1st Sum 2010')     
ORDER BY Term; 

it is very poor practice to use select *.使用 select * 是非常糟糕的做法。 It causes performance problems.它会导致性能问题。

Why are you using IN?你为什么用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.首先是 tblProcInfo 中没有与 tblPernfo 中的记录匹配的记录。 You can confirm or exclude this possibility by running the statement without the where clause.您可以通过运行不带 where 子句的语句来确认或排除这种可能性。

SELECT (specify columns here)     
FROM tblPernfo 
INNER JOIN tblProcInfo ON tblProcInfo.eID=tblPernfo.eID   

If it returns records, the where clause is the issue, if it does not the join ins the issue.如果它返回记录,则 where 子句是问题,如果它不返回则连接问题。 Next run this ( or substitute tblProcInfo idf that is the table that contains the Term column:接下来运行此 ( 或替换 tblProcInfo idf ,即包含 Term 列的表:

SELECT (specify columns here)     
FROM tblPernfo   
WHERE Term In ('1st Sum 2010')     

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.如果返回数据并且第一个查询返回记录,那么剩下的唯一可能性是第二个表中没有与该特定值的第一个表匹配的记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM