Nyx Assasin Nyx Assasin - 4 months ago 8
Vb.net Question

Display Data from Two Tables but the 2nd Table has more Data than the 1st One

Good Afternoon.

I have two Tables in MySQL and they are.

Table 1: purchorder

+-----------+------------------------+----------+
| ItemCode | Description | OrderQty |
+-----------+------------------------+----------+
| HKQSLUWKN | 1 Computer Set DDR3 | 30.00 |
| SORHFRBPJ | Operations Logs System | 40.00 |
| OP8XMREC0 | 12 Ream Bond Paper | 50.00 |
| CPD5CGDZ3 | Ajinomoto Seasoning | 60.00 |
+-----------+------------------------+----------+
4 rows in set (0.00 sec)


Table 2: receiving

+-----------+------------------------+---------+---------+
| ItemCode | Description | QtyPack | QtyStan |
+-----------+------------------------+---------+---------+
| HKQSLUWKN | 1 Computer Set DDR3 | 5.00 | 4.00 |
| SORHFRBPJ | Operations Logs System | 40.00 | 0.00 |
| HKQSLUWKN | 1 Computer Set DDR3 | 24.96 | 0.00 |
| OP8XMREC0 | 12 Ream Bond Paper | 50.00 | 0.00 |
| CPD5CGDZ3 | Ajinomoto Seasoning | 60.00 | 0.00 |
+-----------+------------------------+---------+---------+
5 rows in set (0.00 sec)


My Question is How can I display this 2 tables together like this?

Please See the Image Here

You know, Display the Data from
Table: purchorder
in the Left Side together with the data from
Table: receiving
in the Right but my problem here is the Data from
Table: receiving
has 2 more and it will be possible happen to other data`s also (Please check the Image above)

I will be using the Criteria of
purchorder.ItemCode=receiving.ItemCode
and
purchorder.PONO = 'PO787HZN'


Here is the Possible Output that I need and If this will not work in Database is it Possible to work on VB.Net Datagridview?

Please See the Image Here

TYSM for future help and I hope you get my point.

Answer

You can use join

Inner join if all the itemCode match

select a.*, b.* 
from table1 as a 
inner join table2 as b on a.ItemCode = b.ItemCode  ;

Left join if not all the itemCode match

select a.*, b.* 
from table1 as a 
left join table2 as b on a.ItemCode = b.ItemCode  ;