简体   繁体   中英

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

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

在此处输入图像描述

What i tried is

I need sql select query to get the result shown above

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

where 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 master.voucherkey, detail.Amount
FROM master
LEFT JOIN detail
ON master.voucherkey = detail.voucherkey

SQL cannot return merged rows like the picture.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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