我如何在一个表中添加两个表来输出

编程入门 行业动态 更新时间:2024-10-11 17:20:35
本文介绍了我如何在一个表中添加两个表来输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两张桌子1和桌子。 table1 id name table2 排名位置 i想输出一个表3 table3 id名称排名位置 以上两个表存在于数据库文件中, i希望通过使用visual studio c#

i have two tables table1 and table. table1 id name table2 rank postion i want to output a table3 table3 id name rank position the above two table exist in database file, i want to create table3 in database by using visual studio c#

推荐答案

在数据库中创建table3。你不能处于当前状态。重新研究你的表格设计,回答这些问题: 1.每个表的主键是什么; 2. 2个表如何相关(链接) ,即主键< =>外键 参考: Relational_Database_Design [ ^ ] You can't at the present state. Re-look into your tables design, answers these questions: 1. What is the primary key for each table; 2. How do the 2 tables related (linked), i.e. primary key <=> foreign key Refer: Relational_Database_Design[^]

你的table2需要有一个外键id到表1.我不得不猜测你提供的有限信息表2有一个名为table1_id的字段。然后你可以这样做: Your table2 needs to have a foreign key id to table 1. I would have to guess on the limited information you provided that table 2 has a field named something like table1_id. Then you can just do this: SELECT table1.id, table1,name, table2.rank, table2.position FROM table1 LEFT JOIN table2 ON table1.id = table2.table1_id

您需要在表格之间建立关系,否则您最终会得到一些可能无意义数据的交叉连接。

You need to have a relationship between the tables or else you end up with some cross join that would likely be meaningless data.

更多推荐

我如何在一个表中添加两个表来输出

本文发布于:2023-10-08 01:07:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471061.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!