SQL Join 返回空集

发布于 2024-11-30 06:23:35 字数 307 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄暮涼年 2024-12-07 06:23:35

首先,

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

使用 select * 是非常糟糕的做法。它会导致性能问题。

你为什么使用IN? = 应该可以。

现在来了解为什么没有返回记录。这是一个简单的数据集,因此只有几种可能性。首先,tblProcInfo 中没有与 tblPernfo 中的记录匹配的记录。您可以通过运行不带 where 子句的语句来确认或排除这种可能性。

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

如果它返回记录,则 where 子句是问题,如果它不返回记录,则问题是 join in。接下来运行此(或替换 tblProcInfo idf,它是包含 Term 列的表:

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

如果返回数据并且第一个查询返回记录,那么剩下的唯一可能性是第二个表中没有与第一个表匹配的记录具体值。

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 *. 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.

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. Next run this ( or substitute tblProcInfo idf that is the table that contains the Term column:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文