left join - SQL Query Joining Tables, Getting Duplicate -


So I'm trying to get here in several tables. To complete the query I need to get some columns from my final table. However, when I join this final table, I get several rows. After joining the top return, the first is below Enter image details here

These are my queries:

 'PO', AD_NAME, pt_part, pt_desc1 as 'Part Number' as 'Supplier' as 'Code Number' as 'Part Number' The selection in the form of prh_nbr, prh_rcvd 'in the form of volume', (prh_qty_ord as integer), 'quantity ordered' in the form of cast, 'cost as cost' in prh_pur_cost, 'total cost as' (prh_pur_cost * prh_rcvd), cast (e.prh_rcp_date date as) as a left externally qad_repl.dbo.pod_det_sql the 'acquisition date' B as qad_repl.dbo.po_mstr_sql JOIN (a .pod_nbr = b.po_nbr ) Join qad_repl.dbo.ad_mstr_sql JOIN (b.po_vend = c.ad_addr) as the Left External as d on the external qad_repl.dbo.pt_mstr_sql (a.pod_part = d.pt_par T) Join the outer external E (po_nbr = e.prh_nbr) where pt_part is not empty and po_nbr is null and pod_qty_rcvd & gt; qad_repl.dbo.prh_hist_sql; 0 more prh_nbr = 'PO1701' and 'prh_rcp_date' = '2015-01-21' and prh_rcp_date & lt; = '2015-01-22'  

and then for another:

  in the form of 'supplier' as 'po', AD_NAME, pt_part In the selection pod_nbr 'as part number', as a left outer join qad_repl.dbo as 'part statement' pt_desc1 from qad_repl.dbo.pod_det_sql. As po_mstr_sql Left external c (b.po_vend = c.ad_addr) Left outer qad_repl.dbo.ad_mstr_sql Join include the qad_repl.dbo.pt_mstr_sql D (a.pod_part looking = D (a as .pod_nbr = b.po_nbr) b.pt_part) where pt_part is not empty and po_nbr is not empty and pod_qty_rcvd & gt; 0 and pod_nbr = 'PO1701'  

I am not sure how much information you need / need to see, but I am trying to keep it as clean as possible.

When I try to join my last table (PRIHHST_SCL), it seems that I can only join PO number and line number. In the example given above, I had po_nbr, which is why I am getting four rows instead of two rows ... If I do line number, I have been shown this picture, as shown in this picture. ..

Enter image description here

Does anyone Have any idea to help me? If necessary, I can display more information, just ask.

This can work ...

  'po' As the selection prh_nbr, 'part number' pt_part as 'ADWAR' in the form of 'Supplier', as 'part statement' pt_desc1, receive quantity as 'prh_rcvd', cast (prh_qty_ord as integer) as as the volume went, Prh_pur_cost order as '', (prh_pur_cost * prh_rcvd) purchase costs Total costs (max (prh_rcp_date) selected prh_hist_sql where prh_nbr = b.po_nbr and prh_rcp_date & gt; = '2015-01-21' and prh_rcp_date & lt; = a left externally qad_repl.dbo.pod_det_s From ql to '2015-01-22') 'acquisition date' B (a.pod_nbr = b.po_nbr) Left externally qad_repl.dbo.po_mstr_sql Join c Join as qad_repl.dbo.ad_mstr_sql (b. join po_vend = c.ad_addr) Left External D (a.pod_part = d.pt_part) where pt_part is not empty and po_nbr null and qad_repl.dbo.pt_mstr_sql as pod_qty_rcvd is not & gt; 0 and choose prh_nbr = 'PO1701' and exists (1 prh_hist_sql where prh_nbr = b.po_nbr and prh_rcp_date & gt; = '2015-01-21' and prh_rcp_date & lt; = '2015-01-22')  

Instead of joining the history table, use the subqueries to specify the criteria and the field you want (Received Date)


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -