从多个表连接 mysql 4.0 数据的最快方法?

发布于 2024-07-14 18:52:26 字数 303 浏览 2 评论 0原文

我有 3 个 mysql 4.0 表:都有字段 ID(int)、type(int) 和另一个字段 value 可以是 varchar(255)、tinyintint

我需要将它们全部写出来,最终得到三个 DataTable,循环它们,并在临时表中创建行(在 .NET 1.1 中)。

您是否看到比这更快/更干净的方法来加入或只是写出这些数据?

I have 3 mysql 4.0 tables: all have fields ID(int), type(int) and another field, value which is either varchar(255), tinyint or int.

I need to write them all out and I end up getting three DataTables, looping over them, and creating rows into a temporary table (in .NET 1.1).

Do you see any faster/cleaner way than this to join or just write out this data?

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

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

发布评论

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

评论(1

别在捏我脸啦 2024-07-21 18:52:26

我不确定您是否想要在一个查询中实际加入或显示所有三个表的结果。

如果您只是想要平坦的结果,那么最好的方法是进行联合,例如:

SELECT 
    ID, 
    Type, 
    Convert(varchar(255), Value) as Value 
FROM 
    table1
UNION
SELECT 
    ID, 
    Type, 
    Convert(varchar(255), Value) as Value 
FROM 
    table2
UNION
SELECT 
    ID, 
    Type, 
    Convert(varchar(255), Value) as Value 
FROM 
    table3

注意:我正在进行转换,以便您可以获得所有三个字段的最稳定的形式(varchar 版本)。

I am not sure if you are wanting to actually join or display the results from all three tables in one query.

If you are just wanting flat out results, your best best would be to do a union such as:

SELECT 
    ID, 
    Type, 
    Convert(varchar(255), Value) as Value 
FROM 
    table1
UNION
SELECT 
    ID, 
    Type, 
    Convert(varchar(255), Value) as Value 
FROM 
    table2
UNION
SELECT 
    ID, 
    Type, 
    Convert(varchar(255), Value) as Value 
FROM 
    table3

Note: I am doing the convert so that you can get the most stable form (the varchar version) of all three of your fields.

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