delphi DBGrid显示JOIN结果

发布于 2024-12-10 07:45:18 字数 698 浏览 4 评论 0原文

我正在使用 BDS 2006、MySQL DB(用于连接的 MyDAC 组件),并且我的表单上有一个 DBGrid 组件,它显示数据库表中的记录。

现在我需要JOIN两个表并在我的DBGrid中显示结果

我应该得到的结果视图是查询

SELECT e_salary.e_basic,e_details 的结果.e_name 来自电子详细信息 内连接 e_salary ON e_details.e_id=e_salary.e_id;

时,还有一个选项可以做到这一点

当我搜索SELECT e_salary.e_basic,e_details.e_name 从 电子详细信息、电子工资 在哪里 e_details.e_id=e_salary.e_id;

e_details,e_salary 是我的两个表,e_id 是我的主键

目前我有 2 个 DBGrid 一个用于 e_details, e_salary 的其他

是否可以只有 1 个 DBGrid 显示两个表中的值?或者我必须显示 2 个单独的 DBGrid?

如果可能的话,我该怎么做

P.S.-视图中需要添加更多列,并且两个表的行数相同

提前致谢

I am working with BDS 2006,MySQL DB (MyDAC components used for connection) and i have a DBGrid component on my form which displays the records from my DB table.

Now i need to JOIN two tables and display the results in my DBGrid

The Resulting view that I should get is the result of the query

SELECT e_salary.e_basic,e_details.e_name
FROM e_details
INNER JOIN e_salary
ON e_details.e_id=e_salary.e_id;

there is one more option to do it as I searched

SELECT
e_salary.e_basic,e_details.e_name
FROM
e_details, e_salary
WHERE
e_details.e_id=e_salary.e_id;

e_details,e_salary are my two tables and e_id is my PRIMARY KEY

Presently I am having 2 DBGrid one is for e_details and other for e_salary

Is it possible to have only 1 DBGrid displaying values from both the Tables? or I have to display 2 separate DBGrid?

If possible then how do I go about it

P.S.- there are more columns to be added in the view and both tables have same no of rows

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

谁对谁错谁最难过 2024-12-17 07:45:18
  1. DBGrid 显示数据集数据。数据可能是某些 SQL 查询执行的结果。 DBGridTDataSetTDataSource 不关心 SQL 查询是什么。单表 SELECT、带有联接、存储过程调用或 SHOW 命令的多表 SELECT。所以,是的 - 您可以使用 1 个 DBGrid 来显示连接 2 个表的 SELECT 结果集。
  2. 如果两个表具有相同的行数,e_id 是两个表的主键,那么为什么不使用单个表来包含两个表的列呢?此外,如果您需要编辑数据集数据,则更新两个表的列可能会出现问题。这可能是使用单个表的又一个论据。
  3. 尽管您可以使用 WHERE e_details.e_id=e_salary.e_id 而不是 JOIN e_salary ON e_details.e_id=e_salary.e_id。 JOIN 是首选,因为 DBMS 更明确地了解您的意图,并且对其他人来说更具可读性。
  1. DBGrid displays a dataset data. The data may be result of some SQL query execution. DBGrid, TDataSet and TDataSource do not cary what was the SQL query. Single table SELECT, multi table SELECT with joins, stored procedure call or SHOW command. So, yes - you can use 1 DBGrid to display resultset of your SELECT joining 2 tables.
  2. If both tables have the same number of rows, e_id is primary key for both tables, then why not to have single table, containing columns of both tables ? Also, if you will need to edit your dataset data, then there may be problems to update columns of both tables. And that may be one more argument to have single table.
  3. Although you can use WHERE e_details.e_id=e_salary.e_id instead of JOIN e_salary ON e_details.e_id=e_salary.e_id. The JOIN is preferred, because DBMS gets your intent more explicitly and that is more readable for others.
流年里的时光 2024-12-17 07:45:18

DBgrid 可能不是您需要的组件。
关注 TTreeView

http://delphi.about.com/od/vclusing /l/aa060603a.htm

The DBgrid is probably not the component you need.
Give an eye to the TTreeView

http://delphi.about.com/od/vclusing/l/aa060603a.htm

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