如何从两个不同的表中选择列 [英] How do I select columns from two distinct tables

查看:83
本文介绍了如何从两个不同的表中选择列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有DataGrinView的表单,我需要DataGrinView来显示来自2个不同表格的特定列。



我试过这个查询:

I have a form with a DataGrinView and I need that DataGrinView to show me specific columns from 2 distinct tables.

I have tried this query:

<SELECT TransDocument, TransSerial, TransDocNumber, PartyName, PartyLocalityID, TotalAmount, ShipToPostalCode FROM dbo.UXFaturas , dbo.SaleTransaction where Estado = 0

但我得到了这个错误:

but I got this error:

Error trying to create the parameterized query
Invalid column name 'TransDocument1'.
Invalid column name 'TransSerial'.
Invalid column name 'TransDocNumber'.





我正在使用的列的名称不是我的那些调用查询为什么我会收到此错误?如果您需要有关我的SQL数据库的更多信息,请随时询问。



我尝试过:





The names of the columns that I'm using arent the ones I'm calling on the query why do I get this error? If you need more information about my sql database feel free to ask.

What I have tried:

SELECT TransDocument, TransSerial, TransDocNumber, PartyName, PartyLocalityID, TotalAmount, ShipToPostalCode FROM dbo.UXFaturas , dbo.SaleTransaction where Estado = 0

推荐答案

您好,



SQL解析器需要了解哪些列属于哪些表。在你的情况下,你没有具体说明。

所以,首先,你需要为每一列指定,你可以使用别名用于此目的。然后,您需要指定应读取每个表中的哪些数据。为此,您可以使用加入。但是要使用连接,你需要一个在两个表中都很常见的列。



如果没有,你可能想看一下回答这个 CP问题。



谢谢,祝你好运。
Hi,

The SQL parser needs to understand which columns belong to which tables. In your case, you do not specifically say that.
So, first of all, you need to specify that for each column, and you can use aliases for that purpose. Then you need to specify which data from each table should be read. For that, you can use joins. But to use joins, you will need a column that is common in both the tables.

If there aren't any, you might want to take a look at the answer to this CP question.

Thanks and good luck.


这篇关于如何从两个不同的表中选择列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆