使用带有内连接的where子句 [英] Using where clause with inner joins
问题描述
为什么此查询没有使用where子句给出结果。如果我不使用where子句,那么我会得到一些结果,但是我不想使用full我想使用where子句。
任何人都可以帮助我吗?
SELECT dbo.Employees.FirstName,dbo.Employees.LastName,dbo.Signatures.Employee_ID,dbo.Signatures.Document_ID, dbo.Documents.Topic,Documents.Created,
dbo.Documents.RevisionLevel
FROM dbo.Employees INNER JOIN
dbo.Signatures ON dbo .Signatures.Employee_ID = dbo.Employees.ID INNER JOIN
dbo.Documents ON dbo.Signatures.Document_ID = dbo.Documents.ID
其中Documents.Complete = 0
我尝试过:
Sql server内连接where where子句
Why this query is not giving a result with where clause. If I don't use where clause then I get some results but that does not use full for me I want to use where clause.
Can anyone help me, please?
SELECT dbo.Employees.FirstName, dbo.Employees.LastName, dbo.Signatures.Employee_ID, dbo.Signatures.Document_ID, dbo.Documents.Topic,Documents.Created,
dbo.Documents.RevisionLevel
FROM dbo.Employees INNER JOIN
dbo.Signatures ON dbo.Signatures.Employee_ID = dbo.Employees.ID INNER JOIN
dbo.Documents ON dbo.Signatures.Document_ID = dbo.Documents.ID
where Documents.Complete = 0
What I have tried:
Sql server inner joins with where clause
推荐答案
你可以尝试类似
you can try something like
SELECT
Complete
,COUNT(0) AS cnt
FROM Documents
GROUP BY
Complete
ORDER BY 2 DESC
这会让你知道作为where子句可能有意义的值。
考虑下面的评论,你可以添加
this will give you an idea of the values that might make sense as a where clause.
Taking your comment below into account, you can add
CASE WHEN Documents.Complete = 0 THEN 'pending'
WHEN Documents.Complete = 1 THEN 'has completed'
ELSE 'something strange happend'
END AS DocumentStatus
列列表(并且不使用where子句)。但是根据你写的内容,我不确定你想要的输出应该是什么样的。
to your column list (and don't use the where clause). But from what you wrote I'm not sure what your desired output should look like.
如果添加WHERE子句不返回任何行,那么因为没有符合条件的JOINed行。我们无法解决这个问题:它是您的数据,我们无权访问。
添加dbo.Documents.Complete
到您的SELECT列表,并删除WHERE子句。
运行查询,您将看到WHERE将要处理的所有JOINed行都不匹配 - 以获得结果你想要的,你将不得不查看其余的数据,并找出原因,我们不能这样做!
If adding the WHERE clause returns no rows, then it's because there are no JOINed rows that match the criteria. There isn't anything we can do to fix that: it's your data, and we don't have access to that.
Adddbo.Documents.Complete
to your SELECT list, and remove the WHERE clause.
Run the query, and you will see that none of the JOINed rows that the WHERE would be working on would match - to get the results you want, you will have to look at the rest of your data and isolate why that is the case, and we can't do that!
这篇关于使用带有内连接的where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!