Click here to Skip to main content
15,891,033 members
Home / Discussions / Database
   

Database

 
AnswerRe: compare performance between two query Pin
Tim Carmichael5-Apr-13 3:11
Tim Carmichael5-Apr-13 3:11 
AnswerRe: compare performance between two query Pin
PIEBALDconsult5-Apr-13 3:21
mvePIEBALDconsult5-Apr-13 3:21 
SuggestionRe: compare performance between two query Pin
Eddy Vluggen5-Apr-13 7:21
professionalEddy Vluggen5-Apr-13 7:21 
GeneralRe: compare performance between two query Pin
mhd.sbt5-Apr-13 8:44
mhd.sbt5-Apr-13 8:44 
GeneralRe: compare performance between two query Pin
Eddy Vluggen5-Apr-13 8:54
professionalEddy Vluggen5-Apr-13 8:54 
GeneralRe: compare performance between two query Pin
mhd.sbt5-Apr-13 9:01
mhd.sbt5-Apr-13 9:01 
GeneralRe: compare performance between two query Pin
Eddy Vluggen5-Apr-13 9:04
professionalEddy Vluggen5-Apr-13 9:04 
QuestionJOIN 3 Tables Pin
Richard.Berry1004-Apr-13 19:01
Richard.Berry1004-Apr-13 19:01 
Hi
I wonder if you could assist with a JOIN on three tables. I just cant see where I am going wrong.

StkQty Join Stk History - WORKS
SQL
SELECT tStk.WH + ' - ' + tStk.StockCode as [WP],  tHst.HstTot
FROM stock_qty AS tStk
LEFT JOIN (SELECT stock_history.Location + ' - ' + stock_history.StockCode AS [WP], sum(stock_history.Qty) as [HstTot]
FROM stock_history
GROUP BY stock_history.Location+ ' - ' + stock_history.StockCode) AS [tHst] ON  tHst.WP =tStk.WH + ' - ' + tStk.StockCode
GROUP BY  tStk.WH + ' - ' + tStk.StockCode,tHst.HstTot


StkQty Join SalesOrders - WORKS
SQL
SELECT tStk.WH + ' - ' + tStk.StockCode as [WP], tSO.SoTot
FROM stock_qty AS tStk
LEFT JOIN (SELECT sales_order_header.Wh + ' - ' +  sales_order_detail.StockCode as [WP], sum(sales_order_detail.QtyDespatched) as [SoTot]
FROM sales_order_detail, sales_order_header WHERE sales_order_detail.SalesOrder = sales_order_header.SalesOrder
GROUP BY sales_order_header.Wh + ' - ' +  sales_order_detail.StockCode) as tSO ON tSO.WP = tStk.WH + ' - ' + tStk.StockCode
GROUP BY  tStk.WH + ' - ' + tStk.StockCode,tSO.SoTot


StQty JOIN StkHistory JOIN SalesOrders - FAIL Syntax Error (missing operator)...
SQL
SELECT tStk.WH + ' - ' + tStk.StockCode as [WP], tSO.SoTot, tHst.HstTot
FROM stock_qty AS tStk
LEFT JOIN (SELECT sales_order_header.Wh + ' - ' +  sales_order_detail.StockCode as [WP], sum(sales_order_detail.QtyDespatched) as [SoTot]
FROM sales_order_detail, sales_order_header WHERE sales_order_detail.SalesOrder = sales_order_header.SalesOrder
GROUP BY sales_order_header.Wh + ' - ' +  sales_order_detail.StockCode) as tSO ON tSO.WP = tStk.WH + ' - ' + tStk.StockCode
LEFT JOIN (SELECT stock_history.Location + ' - ' + stock_history.StockCode AS [WP], sum(stock_history.Qty) as [HstTot]
FROM stock_history
GROUP BY stock_history.Location+ ' - ' + stock_history.StockCode) AS [tHst] ON  tHst.WP =tStk.WH + ' - ' + tStk.StockCode
GROUP BY  tStk.WH + ' - ' + tStk.StockCode, tSO.SoTot, tHst.HstTot

AnswerRe: JOIN 3 Tables Pin
Mycroft Holmes4-Apr-13 20:04
professionalMycroft Holmes4-Apr-13 20:04 
GeneralRe: JOIN 3 Tables Pin
Richard.Berry1005-Apr-13 2:49
Richard.Berry1005-Apr-13 2:49 
GeneralRe: JOIN 3 Tables Pin
Mycroft Holmes5-Apr-13 13:12
professionalMycroft Holmes5-Apr-13 13:12 
GeneralRe: JOIN 3 Tables Pin
Richard.Berry1005-Apr-13 23:41
Richard.Berry1005-Apr-13 23:41 
GeneralRe: JOIN 3 Tables Pin
Mycroft Holmes6-Apr-13 14:14
professionalMycroft Holmes6-Apr-13 14:14 
QuestionSQL QUERY Pin
girijeshkumar3-Apr-13 20:08
girijeshkumar3-Apr-13 20:08 
AnswerRe: SQL QUERY Pin
i.j.russell3-Apr-13 21:36
i.j.russell3-Apr-13 21:36 
GeneralRe: SQL QUERY Pin
girijeshkumar3-Apr-13 23:05
girijeshkumar3-Apr-13 23:05 
GeneralRe: SQL QUERY Pin
i.j.russell4-Apr-13 2:07
i.j.russell4-Apr-13 2:07 
AnswerRe: SQL QUERY Pin
Bernhard Hiller3-Apr-13 21:38
Bernhard Hiller3-Apr-13 21:38 
GeneralRe: SQL QUERY Pin
girijeshkumar3-Apr-13 23:07
girijeshkumar3-Apr-13 23:07 
AnswerRe: SQL QUERY Pin
ritesh.gupta55553-Apr-13 22:28
ritesh.gupta55553-Apr-13 22:28 
GeneralRe: SQL QUERY Pin
girijeshkumar3-Apr-13 22:58
girijeshkumar3-Apr-13 22:58 
GeneralRe: SQL QUERY Pin
ritesh.gupta555525-Jun-13 2:55
ritesh.gupta555525-Jun-13 2:55 
QuestionSQL QUERY Pin
Dobrobit2-Apr-13 8:41
Dobrobit2-Apr-13 8:41 
AnswerRe: SQL QUERY Pin
David Mujica2-Apr-13 9:12
David Mujica2-Apr-13 9:12 
AnswerRe: SQL QUERY Pin
Corporal Agarn2-Apr-13 9:17
professionalCorporal Agarn2-Apr-13 9:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.