简体   繁体   English

合并两个不同的表

[英]Combine two different tables

I have 3 tables. 我有3张桌子。 One contains details of items, Second contains selling details and the third one contains the purchase details. 一个包含项目的详细信息,第二个包含销售的详细信息,第三个包含购买的详细信息。 I want to create query which displays a ledger type result. 我想创建显示分类帐类型结果的查询。 I have tried it but the following query is giving a warning like: Current selection does not contain a unique column. 我已经尝试过了,但是以下查询给出了类似的警告:当前选择不包含唯一列。

The result table will also contain a column to identify from which table it is picking the values. 结果表还将包含一列,以标识从哪个表中选择值。 Like, it will put "P" for purchase and "S" for sale. 像这样,它将以"P"表示购买,以"S"表示出售。

I have searched everything but I am not able to find a solution in my case. 我已经搜索了所有内容,但无法找到解决方案。 Here is the query: 这是查询:

SELECT date,
       itemcode,
       qty,
       billno,
       price,
       "p" AS SP
FROM   purchase
WHERE  itemcode = 1007
UNION ALL
SELECT date,
       itemcode,
       qty,
       billno,
       rate,
       "s"
FROM   billing
WHERE  itemcode = 1007
ORDER  BY date ASC 

SELECT date,itemcode,qty,billno,price,null AS rate,“ p” AS SP FROM Purchase WHERE itemcode = 1007 UNION ALL选择date,itemcode,qty,billno,null AS price,rate,“ s” AS SP FROM billing项目代码= 1007订单日期日期ASC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM