mysql - 显示两个表中的数据并消除重复项

标签 mysql vb.net datagridview

下午好。在提出问题之前,我想向您展示我的数据库和表。

我在 MySQL 中有两个表

表1:采购订单

enter image description here

表2:接收

enter image description here

正如您在第一个表中看到的那样,表 pucrhorder 中的 RINumbeR 已在表 receiving 中更新。现在我的目标是做这样的事情。

enter image description here

在发布这个问题之前,我尝试对其进行编码,但我的输出是这样的:

enter image description here

其代码是:

 Private Sub POHistory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim con1 As MySqlConnection = New MySqlConnection("server=localhost;userid=root;password=admin1950;database=inventory")
        Dim sql1 As MySqlCommand = New MySqlCommand("select purchorder.PONo,purchorder.ItemCode,purchorder.Description,purchorder.OrderQty,receiving.RINo,receiving.ItemCode,receiving.Description,receiving.ReceivedQty from purchorder,receiving where Purchorder.PONo = '" & TextBox1.Text & "' = receiving.RINo = '" & TextBox2.Text & "' GROUP BY Purchorder.ItemCode;", con1)
        Dim ds1 As DataSet = New DataSet
        Dim adapter1 As MySqlDataAdapter = New MySqlDataAdapter
        con1.Open()
        adapter1.SelectCommand = sql1
        adapter1.Fill(ds1, "MyTable")
        DataGridView1.DataSource = ds1.Tables(0)
        con1.Close()
    End Sub

该怎么办?我需要在 MYSQL 中使用连接吗? Datagridview 油漆?任何帮助表示赞赏。我想要的只是显示如上图所示的数据(带有黄色标题)

TYSM

最佳答案

是的,如果您使用 JOIN 和 GROUP BY,您将获得两个表的结果,并且您分组的列上没有重复

关于mysql - 显示两个表中的数据并消除重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38158339/

相关文章:

c# - 为什么 Columns 在调用 DataGridView.Columns.Clear() 后不保持隐藏状态?

php - 尝试为 mysql 编写一个 PHP 函数 SELECT SUM()

python - MySql 查询的 Flask HTML 表单字段在 macOS Sierra 上返回错误

asp.net - IF 运算符与 If、then、else 之间的计算差异

vb.net - 无需下载即可从 url 在图像框中设置图像

C# 窗体 : Relative position of growing elements c# windows forms

mysql - 用参数显示两个不同时间之间的所有时间

php - 使用 php 在导航菜单中设置文件权限

vb.net - 使用 CType 与 VB.net 单选返回额外的数字

c# - DataGridView自动生成列