使用sql从两个表的表中检索数据 [英] To retrieve data from table of two tables using sql
本文介绍了使用sql从两个表的表中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
查找表格
Dear All,
Find the tables
VNumbers
(
VNumber nvarchar(max),
Amount nvarchar(max)
)
Submittable
(
Snumber nvarchar(max),
Amount nvarchar(max)
)
VNumbers已经拥有reords如下
VNumbers is already having reords as below
VNumber | Amount
1001 | 100
1002 | 100
1003 | 100
1004 | 100
SubmitTable为空。现在在Snumber字段中的SubmitTable中插入值1001以从VNumbers表中检索金额(100)。
但是以下查询无效。请回复我,下面的查询中哪里有错误,还有其他方法吗?
SubmitTable is empty. Now inserting value 1001 in SubmitTable in Snumber field to retrieve amount (100) from VNumbers table.
But below query is not working. Please reply me, where is mistake in below query and is there another way?
select VNumbers.amount from VNumbers inner join submitTable on VNumbers.VNumber=submitTable.VNumber where VNumbers.VNumber=1001
推荐答案
您正在使用VNumbers.VNumber = submitTable.VNumber加入两个表
withINNER JOIN
。只要两个表中的列之间存在匹配,INNER JOIN关键字就会选择两个表中的所有行。您可以使用LEFT JOIN
连接两个表。
LEFT JOIN关键字返回左表中的所有行(VNumbers),即使有右表中没有匹配(SubmitTable)
阅读本文le b / b
SQL LEFT JOIN
VNumbers.VNumber = submitTable.VNumber
应更正为
VNumbers.VNumber = submitTable.SNumber
[/ EDIT]
You are joining both tables usingVNumbers.VNumber=submitTable.VNumber
withINNER JOIN
.The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables.you can useLEFT JOIN
to connect both tables.
The LEFT JOIN keyword returns all the rows from the left table (VNumbers), even if there are no matches in the right table (SubmitTable)
Read this article
SQL LEFT JOIN
VNumbers.VNumber=submitTable.VNumber
should be corrected as
VNumbers.VNumber=submitTable.SNumber
[/EDIT]
查看这个...
Hi,
Check this one...
SELECT V.amount from VNumbers V, submitTable S
WHERE S.Snumber=V.VNumber and S.Snumber=1001
--or V.Vnumber=1001
您的查询中的字段名称似乎是submitTable.VNumber。
我希望这会对你有所帮助。
干杯
It seems to be wrong field name in your query as "submitTable.VNumber".
I hope this will help you.
Cheers
这篇关于使用sql从两个表的表中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文