从一个水晶报告中的多个表中获取数据

时间:2016-01-14 02:51:06

标签: mysql vb.net

我有2张桌子 tbl_issued tbl_transaction

tbl_issued 的列有 ItemID 商品序列数量大小 tbl_transaction 的列已发布已接收已批准部门

我的问题是我想在1个查询中获取它们的列,这是mysql查询

SELECT `ItemID`,`Item`,`Serial`,`Quantity`,`Size`,`Class`,`Unit`,(SELECT `Released`  FROM `tbl_transaction` WHERE `TransactionID` = 12458952) AS `Released`,
(SELECT `Received`  FROM `tbl_transaction` WHERE `TransactionID` = 12458952) AS `Received`,
(SELECT `Approved`  FROM `tbl_transaction` WHERE `TransactionID` = 12458952) AS `Aprroved`,
(SELECT `Department`  FROM `tbl_transaction` WHERE `TransactionID` = 12458952) AS `Department`
FROM `tbl_issued` WHERE `TransactionID` =  12458952

但是在vb.net上传输它不会提供输出。

我将如何将此查询翻译为vb.net的任何想法?在此先感谢您的帮助!

result  from query = "SELECT * FROM tbl_issued WHERE TransactionID =  12458952"

1 个答案:

答案 0 :(得分:0)

我不知道你想要做什么,但如果你想简化它,请按照以下方式进行。你有没有试过内连?就是这样。

SELECT ItemID, Item, Serial, Quantity, Size, Class, Unit, Released, Received,
Approved, Deparment from tbl_issued a INNER JOIN tbl_transaction b on 
a.TransactionID = b.TransactionID Where a.TransactionID = 12458952

我假设两个表都基于您的查询具有TransactionID。