Here is my query. I removed the table names along with other things I am selecting just to make it easier to read.
Select
b.Key1,
b.Key2
From
b
left join c
on c.MailingKey = b.MailingKey
left join d
on d.OrderLineKey = c.OrderLineKey
left join e
on e.ShipKey = d.ShipKey
left join g
on d.ShipKey5 = g.ShipKey5
left join a
on a.DocKey = b.OrderKey
left join f
on f.pMethKey = b.MethKey
I need to use Key1 and Key2 that I select in another query to get more information about that key (location, ID, etc.) from another table. I am thinking I will need to make 2 loops within this original query and join them all up. So something like this:
Select b.Key1, b.Key2, h.*, i.*
From b left join
c on c.MailingKey = b.MailingKey left join
d on d.OrderLineKey = c.OrderLineKey left join
e on e.ShipKey = d.ShipKey left join
g on d.ShipKey5 = g.ShipKey5 left join
a on a.DocKey = b.OrderKey left join
f on f.pMethKey = b.MethKey left join
(
Select*
From table l
Where ID = b.Key1
) h left join (
Select*
From table l
Where ID = b.Key2
) i
I am just not sure how to write equal to b.Key1 and b.Key2.
I am using Microsoft Sql Server Management.
Common table expression:
with cte as (
Select b.Key1, b.Key2
From b left join
c on c.MailingKey = b.MailingKey left join
d on d.OrderLineKey = c.OrderLineKey left join
e on e.ShipKey = d.ShipKey left join
g on d.ShipKey5 = g.ShipKey5 left join
a on a.DocKey = b.OrderKey left join
f on f.pMethKey = b.MethKey)
Select * from CTE
INNER JOIN othertable o
on b.key1=o.key1
and b.key2=o.key2
or do you mean...
Inline view:
Select *
from otherTable
INNER JOIN (
Select b.Key1, b.Key2
From b left join
c on c.MailingKey = b.MailingKey left join
d on d.OrderLineKey = c.OrderLineKey left join
e on e.ShipKey = d.ShipKey left join
g on d.ShipKey5 = g.ShipKey5 left join
a on a.DocKey = b.OrderKey left join
f on f.pMethKey = b.MethKey) CTE
on b.key1=o.key1
and b.key2=o.key2
Or do you mean.... something else?
Perhaps:... using an OR statement...
Select *
from otherTable o
INNER JOIN (
Select b.Key1, b.Key2
From b left join
c on c.MailingKey = b.MailingKey left join
d on d.OrderLineKey = c.OrderLineKey left join
e on e.ShipKey = d.ShipKey left join
g on d.ShipKey5 = g.ShipKey5 left join
a on a.DocKey = b.OrderKey left join
f on f.pMethKey = b.MethKey) CTE
on o.key1=cte.key1
OR o.key2=cte.key2
or maybe... an in statement (within this set)
Select *
from otherTable o
INNER JOIN (
Select b.Key1, b.Key2
From b left join
c on c.MailingKey = b.MailingKey left join
d on d.OrderLineKey = c.OrderLineKey left join
e on e.ShipKey = d.ShipKey left join
g on d.ShipKey5 = g.ShipKey5 left join
a on a.DocKey = b.OrderKey left join
f on f.pMethKey = b.MethKey) CTE
on o.key1 IN (cte.key1, cte.key2)
Related
I am using SQL query but query resulted 12 lines, needs to be 3 lines; I can't figure it out.
Not working query:
SELECT g.*
,c.TxtFobFiyati
,C.TxtTalepETeslimTarihi
,c.TslParaBirimi
,c.TxtFiyat
,C.TslDepoKodu
,c.TslOlcuBirimi AS 'Olcu'
,j.TxtAmbalajDara
,j.TxtPaletDara
,g.TxtAdet AS 'ambalajAdet'
,g.TxtPaletSayisi AS 'paletSayisi'
,j.TxtAmbalajAdi
,J.TxtAmbalajNetKG
,j.TxtBoxGrossWeight
,C.TxtAciklama AS 'KalemAciklama'
,G.TxtAciklama AS 'KalemAciklama2'
,g.TxtPaletUstu AS 'PaletUstu'
,g.TxtPaletSayisi AS 'PaletSayisi'
,c.TxtUrunAdiEng AS 'UrunAdi_Ingilizce'
,C.TxtFobFiyati AS 'FobFiyati'
,j.TslPaletTipi AS 'PaletTipi'
,j.TxtPaletDara AS 'PaletDara'
FROM E_KT_SAS_Form A
LEFT JOIN E_KT_SAS_Form_DtyUrunler2 B
ON A.ID = B.FORMID
LEFT JOIN E_KT_SAS_FrmSipUrunEkle C
ON B.DOCUMENTID = C.ID
LEFT JOIN E_KT_SAS_Form_DtyTeyitEdilen2 D
ON A.ID = D.FORMID
LEFT JOIN E_KT_SAS_FrmUretimTarihiEkle E
ON D.DOCUMENTID = E.ID
AND E.TslUrun = C.TslUrunKodu
LEFT JOIN E_KT_SAS_Form_DtySevkiyatlar F
ON A.ID = F.FORMID
LEFT JOIN E_KT_SAS_FrmSevkiyatEkle G
ON F.DOCUMENTID = G.ID
LEFT JOIN E_KT_SAS_FrmSipUrunEkle_DtyAmbalajlama H
ON C.ID = H.FORMID
LEFT JOIN E_KT_SAS_FrmUrunAmbalajlama J
ON H.DOCUMENTID = J.ID
WHERE E.TslOnay_TEXT = 'Evet'
AND C.TslUrunKodu = G.TslUrun
AND A.ID = 11682
Not working result
Correct result table
Step1) Start count with the driver table i.e. the one you have alias as 'A'. Check the count if you get 3. Continue.
Repeat step 1 with each new join and see where your count blows up to 12. That is your troubling join. Comment it out if possible and continue with joins. If you cannot do successive joins then find best solution to bring count back down to 3.
If your sure of your where clause great; else start without it too. If count is more than 3. Pop it back in.
select count(1)
FROM E_KT_SAS_Form A
LEFT JOIN E_KT_SAS_Form_DtyUrunler2 B ON A.ID = B.FORMID
LEFT JOIN E_KT_SAS_FrmSipUrunEkle C ON B.DOCUMENTID = C.ID
LEFT JOIN E_KT_SAS_Form_DtyTeyitEdilen2 D ON A.ID = D.FORMID
LEFT JOIN E_KT_SAS_FrmUretimTarihiEkle E ON D.DOCUMENTID = E.ID
AND E.TslUrun = C.TslUrunKodu
LEFT JOIN E_KT_SAS_Form_DtySevkiyatlar F ON A.ID = F.FORMID
LEFT JOIN E_KT_SAS_FrmSevkiyatEkle G ON F.DOCUMENTID = G.ID
LEFT JOIN E_KT_SAS_FrmSipUrunEkle_DtyAmbalajlama H ON C.ID = H.FORMID
LEFT JOIN E_KT_SAS_FrmUrunAmbalajlama J ON H.DOCUMENTID = J.ID
WHERE E.TslOnay_TEXT = 'Evet' AND C.TslUrunKodu = G.TslUrun AND A.ID = 11682
I have View called VW_STOCKOPNAME
CREATE OR REPLACE VIEW VW_STOCKOPNAME AS SELECT
A.M_STOCKCODE_KL_ID,
A.M_STOCKCODE_JB_ID,
A.M_STOCKCODE_NB_ID,
A.M_STOCKCODE_SB_ID,
B."NAME" AS S1_KL,
C."NAME" AS S2_JB,
D."NAME" AS S3_NB,
E."NAME" AS S4_SB,
A.M_ASSETCODE_GOLONGAN_ID,
A.M_ASSETCODE_BIDANG_ID,
A.M_ASSETCODE_KELOMPOK_ID,
A.M_ASSETCODE_SUBKELOMPOK_ID,
A.M_ASSETCODE_SUBSUBKEL_ID,
F."NAME" AS A1_GOLONGAN,
G."NAME" AS A2_BIDANG,
H."NAME" AS A3_KELOMPOK,
I."NAME" AS A4_SUBKELOMPOK,
J."NAME" AS A5_SUBSUBKEL,
A.M_PRODUCT_ID,
K."NAME" AS PRODUCT,
L."NAME" AS UOM,
A.QTYBOOK,
A.QTYCOUNT,
A.DIFFERENCE,
N.M_WAREHOUSE_ID,
O."NAME" AS WAREHOUSE
FROM M_INVENTORYLINE A
LEFT JOIN M_STOCKCODE_KL B ON B.M_STOCKCODE_KL_ID = A.M_STOCKCODE_KL_ID
LEFT JOIN M_STOCKCODE_JB C ON C.M_STOCKCODE_JB_ID = A.M_STOCKCODE_JB_ID
LEFT JOIN M_STOCKCODE_NB D ON D.M_STOCKCODE_NB_ID = A.M_STOCKCODE_NB_ID
LEFT JOIN M_STOCKCODE_SB E ON E.M_STOCKCODE_SB_ID = A.M_STOCKCODE_SB_ID
LEFT JOIN M_ASSETCODE_GOLONGAN F ON F.M_ASSETCODE_GOLONGAN_ID = A.M_ASSETCODE_GOLONGAN_ID
LEFT JOIN M_ASSETCODE_BIDANG G ON G.M_ASSETCODE_BIDANG_ID = A.M_ASSETCODE_BIDANG_ID
LEFT JOIN M_ASSETCODE_KELOMPOK H ON H.M_ASSETCODE_KELOMPOK_ID = A.M_ASSETCODE_KELOMPOK_ID
LEFT JOIN M_ASSETCODE_SUBKELOMPOK I ON I.M_ASSETCODE_SUBKELOMPOK_ID = A.M_ASSETCODE_SUBKELOMPOK_ID
LEFT JOIN M_ASSETCODE_SUBSUBKEL J ON J.M_ASSETCODE_SUBSUBKEL_ID = A.M_ASSETCODE_SUBSUBKEL_ID
LEFT JOIN M_PRODUCT K ON K.M_PRODUCT_ID = A.M_PRODUCT_ID
LEFT JOIN C_UOM L ON L.C_UOM_ID = A.C_UOM_ID
LEFT JOIN M_INVENTORY N ON N.M_INVENTORY_ID = A.M_INVENTORY_ID
LEFT JOIN M_WAREHOUSE O ON O.M_WAREHOUSE_ID = N.M_WAREHOUSE_ID
;
I want to add another column which has command as follows :
SELECT S1_KL ||'-'|| S2_JB ||'-'|| S3_NB ||'-'|| S4_SB AS ASSET_CODE
FROM VW_STOCKOPNAME
It shows group of codes from the columns in the view to make it easier to see.
How can I add it?
Try this
CREATE OR REPLACE VIEW VW_STOCKOPNAME AS SELECT
A.M_STOCKCODE_KL_ID,
A.M_STOCKCODE_JB_ID,
A.M_STOCKCODE_NB_ID,
A.M_STOCKCODE_SB_ID,
B."NAME" AS S1_KL,
C."NAME" AS S2_JB,
D."NAME" AS S3_NB,
E."NAME" AS S4_SB,
A.M_ASSETCODE_GOLONGAN_ID,
A.M_ASSETCODE_BIDANG_ID,
A.M_ASSETCODE_KELOMPOK_ID,
A.M_ASSETCODE_SUBKELOMPOK_ID,
A.M_ASSETCODE_SUBSUBKEL_ID,
F."NAME" AS A1_GOLONGAN,
G."NAME" AS A2_BIDANG,
H."NAME" AS A3_KELOMPOK,
I."NAME" AS A4_SUBKELOMPOK,
J."NAME" AS A5_SUBSUBKEL,
A.M_PRODUCT_ID,
K."NAME" AS PRODUCT,
L."NAME" AS UOM,
A.QTYBOOK,
A.QTYCOUNT,
A.DIFFERENCE,
N.M_WAREHOUSE_ID,
O."NAME" AS WAREHOUSE,
B."NAME" ||'-'|| C."NAME" ||'-'|| D."NAME" ||'-'|| E."NAME" AS ASSET_CODE
FROM M_INVENTORYLINE A
LEFT JOIN M_STOCKCODE_KL B ON B.M_STOCKCODE_KL_ID = A.M_STOCKCODE_KL_ID
LEFT JOIN M_STOCKCODE_JB C ON C.M_STOCKCODE_JB_ID = A.M_STOCKCODE_JB_ID
LEFT JOIN M_STOCKCODE_NB D ON D.M_STOCKCODE_NB_ID = A.M_STOCKCODE_NB_ID
LEFT JOIN M_STOCKCODE_SB E ON E.M_STOCKCODE_SB_ID = A.M_STOCKCODE_SB_ID
LEFT JOIN M_ASSETCODE_GOLONGAN F ON F.M_ASSETCODE_GOLONGAN_ID = A.M_ASSETCODE_GOLONGAN_ID
LEFT JOIN M_ASSETCODE_BIDANG G ON G.M_ASSETCODE_BIDANG_ID = A.M_ASSETCODE_BIDANG_ID
LEFT JOIN M_ASSETCODE_KELOMPOK H ON H.M_ASSETCODE_KELOMPOK_ID = A.M_ASSETCODE_KELOMPOK_ID
LEFT JOIN M_ASSETCODE_SUBKELOMPOK I ON I.M_ASSETCODE_SUBKELOMPOK_ID = A.M_ASSETCODE_SUBKELOMPOK_ID
LEFT JOIN M_ASSETCODE_SUBSUBKEL J ON J.M_ASSETCODE_SUBSUBKEL_ID = A.M_ASSETCODE_SUBSUBKEL_ID
LEFT JOIN M_PRODUCT K ON K.M_PRODUCT_ID = A.M_PRODUCT_ID
LEFT JOIN C_UOM L ON L.C_UOM_ID = A.C_UOM_ID
LEFT JOIN M_INVENTORY N ON N.M_INVENTORY_ID = A.M_INVENTORY_ID
LEFT JOIN M_WAREHOUSE O ON O.M_WAREHOUSE_ID = N.M_WAREHOUSE_ID
;
select * from iiasa_inventory.inv_device d
join iiasa_inventory.inv_type ty on d.type_id = ty.id
join iiasa_inventory.inv_category c on ty.category_id = c.id
join iiasa_inventory.inv_device_2_barcode b on b.device_id = d.id
join iiasa_inventory.inv_barcodes bc on b.barcode_id = bc.id
join iiasa_inventory.inv_status s on d.status = s.id
join iiasa_inventory.inv_brand br on ty.brand_id = br.id
left join iiasa_inventory.inv_supplier su on su.id = d.supplier_id
left join iiasa_inventory.inv_supplier sup on sup.id = d.maintenance_with
left join (select distinct device_id from
iiasa_inventory.inv_device_2_persons_cc) dp
on dp.device_id = d.id
where dp.active = 1
I am trying to select my data but the where-clause says that "dp.active" is an INVALID Identifier. This is probably because the table dp is in the subquery. I have tried to give it an alias name and some other things I found while browsing stackoverflow, but I cant seem to find a solution. Any idea?
This is Oracle PL/SQL.
Put the check for active = 1 in the subquery as shown below.
select * from iiasa_inventory.inv_device d
join iiasa_inventory.inv_type ty on d.type_id = ty.id
join iiasa_inventory.inv_category c on ty.category_id = c.id
join iiasa_inventory.inv_device_2_barcode b on b.device_id = d.id
join iiasa_inventory.inv_barcodes bc on b.barcode_id = bc.id
join iiasa_inventory.inv_status s on d.status = s.id
join iiasa_inventory.inv_brand br on ty.brand_id = br.id
left join iiasa_inventory.inv_supplier su on su.id = d.supplier_id
left join iiasa_inventory.inv_supplier sup on sup.id = d.maintenance_with
left join (select distinct device_id from iiasa_inventory.inv_device_2_persons_cc where active = 1) dp on dp.device_id = d.id
That is because you are not selecting active column in dp.
select * from iiasa_inventory.inv_device d
join iiasa_inventory.inv_type ty on d.type_id = ty.id
join iiasa_inventory.inv_category c on ty.category_id = c.id
join iiasa_inventory.inv_device_2_barcode b on b.device_id = d.id
join iiasa_inventory.inv_barcodes bc on b.barcode_id = bc.id
join iiasa_inventory.inv_status s on d.status = s.id
join iiasa_inventory.inv_brand br on ty.brand_id = br.id
left join iiasa_inventory.inv_supplier su on su.id = d.supplier_id
left join iiasa_inventory.inv_supplier sup on sup.id = d.maintenance_with
left join (select distinct device_id,active from iiasa_inventory.inv_device_2_persons_cc) dp on dp.device_id = d.id
where dp.active = 1
OR you can just filter from the subquery itself. Like:
left join (select distinct device_id
from iiasa_inventory.inv_device_2_persons_cc
where active=1) dp on dp.device_id = d.id
I have a query like this:
WITH CTE_KELOMPOKINFORMASI (KelompokInformasi, XBRLItem_ItemId)
AS (
SELECT a.Id AS KelompokInformasi, c.XBRLItem_ItemId
FROM XBRLNamespaces a INNER JOIN XBRLHypercubes b
ON a.XBRLView_ViewId = b.XBRLView_ViewId
INNER JOIN XBRLHypercubeDimensionItems c
ON b.XBRLHypercubeId = c.XBRLHypercube_XBRLHypercubeId
WHERE a.Id like '%KBIK_AAKL%')
SELECT f.KelompokInformasi, e.Name AS DimensionName,
ROW_NUMBER() OVER(PARTITION BY e.Name ORDER BY e.Name DESC) AS 'Number'
FROM XBRLDefinitionRoleDomainItems a
LEFT OUTER JOIN XBRLDefinitionRoleDimensionItems b
ON a.XBRLDefinitionRole_DefinitionRoleId = b.XBRLDefinitionRole_DefinitionRoleId
LEFT OUTER JOIN XBRLItems c ON a.XBRLItem_ItemId = c.ItemId
LEFT OUTER JOIN XBRLLabels d ON a.XBRLItem_ItemId = d.XBRLItem_ItemId
LEFT OUTER JOIN XBRLItems e ON b.XBRLItem_ItemId=e.ItemId
LEFT OUTER JOIN CTE_KELOMPOKINFORMASI f ON b.XBRLItem_ItemId=f.XBRLItem_ItemId
WHERE b.XBRLItem_ItemId=f.XBRLItem_ItemId
and it gives result like this:
Kelompok Informasi DimensionName Number
KBIK_AAKL JWAAKT 1
KBIK_AAKL JWAAKT 2
KBIK_AAKL JWAAKT 3
KBIK_AAKL SNOUPL 1
KBIK_AAKL SNOUPL 2
KBIK_AAKL KOKOLT 1
KBIK_AAKL KOKOLT 2
KBIK_AAKL KOKOLT 3
KBIK_AAKL KOKOLT 4
Is it possible if i DISTINCT my result again by "DimensionName", so i have a result just like this:
KelompokInformasi DimensionName Number
KBIK_AAKL JWAAKT 1
KBIK_AAKL SNOUPL 2
KBIK_AAKL KOKOLT 3
i tried to do distinct like code below but it doesn't work
SELECT DISTINCT DimensionName
FROM (SELECT f.KelompokInformasi, e.Name AS DimensionName,
ROW_NUMBER() OVER(PARTITION BY e.Name ORDER BY e.Name DESC) AS 'Number'
FROM XBRLDefinitionRoleDomainItems a
LEFT OUTER JOIN XBRLDefinitionRoleDimensionItems b
ON a.XBRLDefinitionRole_DefinitionRoleId = b.XBRLDefinitionRole_DefinitionRoleId
LEFT OUTER JOIN XBRLItems c ON a.XBRLItem_ItemId = c.ItemId
LEFT OUTER JOIN XBRLLabels d ON a.XBRLItem_ItemId = d.XBRLItem_ItemId
LEFT OUTER JOIN XBRLItems e ON b.XBRLItem_ItemId=e.ItemId
LEFT OUTER JOIN CTE_KELOMPOKINFORMASI f ON b.XBRLItem_ItemId=f.XBRLItem_ItemId
WHERE b.XBRLItem_ItemId=f.XBRLItem_ItemId)
Use your distinct on the inner subquery and row number them on the outer Select
WITH CTE_KELOMPOKINFORMASI (KelompokInformasi, XBRLItem_ItemId)
AS (
SELECT a.Id AS KelompokInformasi, c.XBRLItem_ItemId
FROM XBRLNamespaces a INNER JOIN XBRLHypercubes b
ON a.XBRLView_ViewId = b.XBRLView_ViewId
INNER JOIN XBRLHypercubeDimensionItems c
ON b.XBRLHypercubeId = c.XBRLHypercube_XBRLHypercubeId
WHERE a.Id like '%KBIK_AAKL%')
Select A.*, ROW_NUMBER() OVER(ORDER BY A.DimensionName DESC) AS 'Number'
FROM (
SELECT distinct f.KelompokInformasi, e.Name AS DimensionName
FROM XBRLDefinitionRoleDomainItems a
LEFT OUTER JOIN XBRLDefinitionRoleDimensionItems b
ON a.XBRLDefinitionRole_DefinitionRoleId = b.XBRLDefinitionRole_DefinitionRoleId
LEFT OUTER JOIN XBRLItems c ON a.XBRLItem_ItemId = c.ItemId
LEFT OUTER JOIN XBRLLabels d ON a.XBRLItem_ItemId = d.XBRLItem_ItemId
LEFT OUTER JOIN XBRLItems e ON b.XBRLItem_ItemId=e.ItemId
LEFT OUTER JOIN CTE_KELOMPOKINFORMASI f ON b.XBRLItem_ItemId=f.XBRLItem_ItemId
WHERE b.XBRLItem_ItemId=f.XBRLItem_ItemId
) AS A
Just Filter with Your Row_Number
Try like this
SELCT KelompokInformasi,DimensionName,ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS 'NUMBER' FROM
(
SELECT f.KelompokInformasi, e.Name AS DimensionName,
ROW_NUMBER() OVER(PARTITION BY e.Name ORDER BY e.Name DESC) AS 'RN'
FROM XBRLDefinitionRoleDomainItems a
LEFT OUTER JOIN XBRLDefinitionRoleDimensionItems b
ON a.XBRLDefinitionRole_DefinitionRoleId = b.XBRLDefinitionRole_DefinitionRoleId
LEFT OUTER JOIN XBRLItems c ON a.XBRLItem_ItemId = c.ItemId
LEFT OUTER JOIN XBRLLabels d ON a.XBRLItem_ItemId = d.XBRLItem_ItemId
LEFT OUTER JOIN XBRLItems e ON b.XBRLItem_ItemId=e.ItemId
LEFT OUTER JOIN CTE_KELOMPOKINFORMASI f ON b.XBRLItem_ItemId=f.XBRLItem_ItemId
WHERE b.XBRLItem_ItemId=f.XBRLItem_ItemId
) AS T
WHERE RN = 1
(OR)
SELCT KelompokInformasi,DimensionName,ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS 'NUMBER' FROM
(
SELECT f.KelompokInformasi, e.Name AS DimensionName,
FROM XBRLDefinitionRoleDomainItems a
LEFT OUTER JOIN XBRLDefinitionRoleDimensionItems b
ON a.XBRLDefinitionRole_DefinitionRoleId = b.XBRLDefinitionRole_DefinitionRoleId
LEFT OUTER JOIN XBRLItems c ON a.XBRLItem_ItemId = c.ItemId
LEFT OUTER JOIN XBRLLabels d ON a.XBRLItem_ItemId = d.XBRLItem_ItemId
LEFT OUTER JOIN XBRLItems e ON b.XBRLItem_ItemId=e.ItemId
LEFT OUTER JOIN CTE_KELOMPOKINFORMASI f ON b.XBRLItem_ItemId=f.XBRLItem_ItemId
WHERE b.XBRLItem_ItemId=f.XBRLItem_ItemId
GROUP BY f.KelompokInformasi, e.Name
) AS T
Its my second day with MS Access, i am trying to update an existing application.
And this includes updating some queries. I never knew it was going to be so complex. the parenthesis issue in Access is really disturbing and i hit the wall, i get the "syntax error" error. My SQL query is something like this :
Select ….(Something)
Into …. (Some Table)
From A
Inner join B on A.ID=B.ID
LEFT OUTER JOIN STAR as C on C.ID = A.ID
AND C.Data = ’DEMO1’
AND C.POS= ’POS1’
LEFT OUTER JOIN STAR as D on D.ID = A.ID
AND D.Data = ’DEMO2’
AND D.POS= ‘POS2’
LEFT OUTER JOIN STAR as E on E.ID = A.ID
AND E.Data = ’DEMO3’
AND E.POS= ‘POS3’
And in access, its equivalent that i am trying is :
Select ….
Into ….
From (((A
Inner join B on A.ID=B.ID)
LEFT OUTER JOIN STAR as C (on C.ID = A.ID
AND C.Data = ’DEMO1’
AND C.POS= ’POS1’)
LEFT OUTER JOIN STAR as D (on D.ID = A.ID
AND D.Data = ’DEMO2’
AND D.POS= ‘POS2’)
LEFT OUTER JOIN STAR as E on E.ID = A.ID
AND E.Data = ’DEMO3’
AND E.POS= ‘POS3’
consider
Select ….
Into ….
From
(A Inner join B on A.ID=B.ID) LEFT OUTER JOIN
STAR as C on
C.ID = A.ID AND
((C.Data = ’DEMO1’ AND C.POS= ’POS1’) OR
(C.Data = ’DEMO2’ AND C.POS= ’POS2’) or
(C.Data = ’DEMO3’ AND C.POS= ’POS3’))
Finally got my way through parenthesis.
Select ….
Into ….
From (((A
Inner join B on A.ID=B.ID)
LEFT OUTER JOIN STAR as C on (C.ID = A.ID
AND C.Data = ’DEMO1’
AND C.POS= ’POS1’))
LEFT OUTER JOIN STAR as D on (D.ID = A.ID
AND D.Data = ’DEMO2’
AND D.POS= ‘POS2’))
LEFT OUTER JOIN STAR as E on (E.ID = A.ID
AND E.Data = ’DEMO3’
AND E.POS= ‘POS3’)