简体   繁体   English

我需要从主人那里获取唯一记录并详细记录其重复记录

[英]I need to Fetch Unique Record from master and with its repeated record in detail

Hello Stackoverflow i am facing problem in join records from master and detail table using Sql Query您好 Stackoverflow,我在使用 Sql 查询从主表和详细表连接记录时遇到问题

Master Table is Represented By Following Data主表由以下数据表示

001002JV 00009/0521 001002JV 00010/0521 001002JV 00011/0521

I Have Data in Detail Table我有明细表中的数据

在此处输入图像描述

What I need in output is我在 output 中需要的是

在此处输入图像描述

What i tried is我尝试的是

I need sql select query to get the result shown above我需要 sql select 查询以获得上面显示的结果

SELECT distinct(master.voucherkey), detail.Amount  FROM master ,detail 

where master.voucherkey = detail.voucherkey其中 master.voucherkey = detail.voucherkey

ie repeated voucherkey once and unique record many time thanks即重复一次凭证密钥和多次唯一记录谢谢

You need to join the tables together rather than trying to select from both:您需要将表格连接在一起,而不是尝试从两者中获得 select:

SELECT master.voucherkey, detail.Amount
FROM master
LEFT JOIN detail
ON master.voucherkey = detail.voucherkey

SQL cannot return merged rows like the picture. SQL 不能像图片一样返回合并的行。

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

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