SQL query doesn't work in my JOIN exercises












0















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



enter image description here



Correct result table



enter image description here










share|improve this question




















  • 2





    I would start by formatting that query. It is a hot mess that nobody wants to unravel. You also should use aliases that help add clarity instead of random letters. sqlblog.org/2009/10/08/…

    – Sean Lange
    Nov 14 '18 at 14:49






  • 1





    Nasty way would be to do SELECT DISTINCT, better way would be to find out why you have duplicate lines, I suspect one or more of your joins are incorrect

    – 3dd
    Nov 14 '18 at 14:49






  • 2





    Your where predicates are turning some of your joins into inner joins. Maybe those predicates should be moved to the join?

    – Sean Lange
    Nov 14 '18 at 14:51






  • 1





    Posting images of data is not very helpful. Why? Also, posting some details to allow others to help would make this better. Here is a great place to start.

    – Sean Lange
    Nov 14 '18 at 15:01






  • 2





    You can always EDIT your post

    – jean
    Nov 14 '18 at 19:51
















0















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



enter image description here



Correct result table



enter image description here










share|improve this question




















  • 2





    I would start by formatting that query. It is a hot mess that nobody wants to unravel. You also should use aliases that help add clarity instead of random letters. sqlblog.org/2009/10/08/…

    – Sean Lange
    Nov 14 '18 at 14:49






  • 1





    Nasty way would be to do SELECT DISTINCT, better way would be to find out why you have duplicate lines, I suspect one or more of your joins are incorrect

    – 3dd
    Nov 14 '18 at 14:49






  • 2





    Your where predicates are turning some of your joins into inner joins. Maybe those predicates should be moved to the join?

    – Sean Lange
    Nov 14 '18 at 14:51






  • 1





    Posting images of data is not very helpful. Why? Also, posting some details to allow others to help would make this better. Here is a great place to start.

    – Sean Lange
    Nov 14 '18 at 15:01






  • 2





    You can always EDIT your post

    – jean
    Nov 14 '18 at 19:51














0












0








0








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



enter image description here



Correct result table



enter image description here










share|improve this question
















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



enter image description here



Correct result table



enter image description here







sql sql-server join left-join inner-join






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 19:37









halfer

14.6k758112




14.6k758112










asked Nov 14 '18 at 14:46









newuseresernewusereser

186




186








  • 2





    I would start by formatting that query. It is a hot mess that nobody wants to unravel. You also should use aliases that help add clarity instead of random letters. sqlblog.org/2009/10/08/…

    – Sean Lange
    Nov 14 '18 at 14:49






  • 1





    Nasty way would be to do SELECT DISTINCT, better way would be to find out why you have duplicate lines, I suspect one or more of your joins are incorrect

    – 3dd
    Nov 14 '18 at 14:49






  • 2





    Your where predicates are turning some of your joins into inner joins. Maybe those predicates should be moved to the join?

    – Sean Lange
    Nov 14 '18 at 14:51






  • 1





    Posting images of data is not very helpful. Why? Also, posting some details to allow others to help would make this better. Here is a great place to start.

    – Sean Lange
    Nov 14 '18 at 15:01






  • 2





    You can always EDIT your post

    – jean
    Nov 14 '18 at 19:51














  • 2





    I would start by formatting that query. It is a hot mess that nobody wants to unravel. You also should use aliases that help add clarity instead of random letters. sqlblog.org/2009/10/08/…

    – Sean Lange
    Nov 14 '18 at 14:49






  • 1





    Nasty way would be to do SELECT DISTINCT, better way would be to find out why you have duplicate lines, I suspect one or more of your joins are incorrect

    – 3dd
    Nov 14 '18 at 14:49






  • 2





    Your where predicates are turning some of your joins into inner joins. Maybe those predicates should be moved to the join?

    – Sean Lange
    Nov 14 '18 at 14:51






  • 1





    Posting images of data is not very helpful. Why? Also, posting some details to allow others to help would make this better. Here is a great place to start.

    – Sean Lange
    Nov 14 '18 at 15:01






  • 2





    You can always EDIT your post

    – jean
    Nov 14 '18 at 19:51








2




2





I would start by formatting that query. It is a hot mess that nobody wants to unravel. You also should use aliases that help add clarity instead of random letters. sqlblog.org/2009/10/08/…

– Sean Lange
Nov 14 '18 at 14:49





I would start by formatting that query. It is a hot mess that nobody wants to unravel. You also should use aliases that help add clarity instead of random letters. sqlblog.org/2009/10/08/…

– Sean Lange
Nov 14 '18 at 14:49




1




1





Nasty way would be to do SELECT DISTINCT, better way would be to find out why you have duplicate lines, I suspect one or more of your joins are incorrect

– 3dd
Nov 14 '18 at 14:49





Nasty way would be to do SELECT DISTINCT, better way would be to find out why you have duplicate lines, I suspect one or more of your joins are incorrect

– 3dd
Nov 14 '18 at 14:49




2




2





Your where predicates are turning some of your joins into inner joins. Maybe those predicates should be moved to the join?

– Sean Lange
Nov 14 '18 at 14:51





Your where predicates are turning some of your joins into inner joins. Maybe those predicates should be moved to the join?

– Sean Lange
Nov 14 '18 at 14:51




1




1





Posting images of data is not very helpful. Why? Also, posting some details to allow others to help would make this better. Here is a great place to start.

– Sean Lange
Nov 14 '18 at 15:01





Posting images of data is not very helpful. Why? Also, posting some details to allow others to help would make this better. Here is a great place to start.

– Sean Lange
Nov 14 '18 at 15:01




2




2





You can always EDIT your post

– jean
Nov 14 '18 at 19:51





You can always EDIT your post

– jean
Nov 14 '18 at 19:51












1 Answer
1






active

oldest

votes


















0














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





share|improve this answer



















  • 1





    Hi. If a question gives a query with a sequence of 8 left joins it is safe to say it should be downvoted & close voted as lacking a Minimal, Complete, and Verifiable example, not answered. Besides, this does not answer the question, it is a tutorial on debugging (which anyway should precede research & entertaining writing a question). Moreover there is no particular reason to expect that the count should stay low as joins are applied, so its approach is flawed.

    – philipxy
    Nov 14 '18 at 22:25













  • clearly one of the tables has 1 to many relationship that is leading to explosion in number of rows returned. All the person who asked the question has to do is above. Because if leave the columns in and now have columns from all 8 different tables; then have to comment each one out. I gave this answer knowing full well user did not supply sample data. Its a path provided to user; if he/she does not want to take it and find answer another way more power to them. ;)

    – junketsu
    Nov 15 '18 at 15:05











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302866%2fsql-query-doesnt-work-in-my-join-exercises%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














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





share|improve this answer



















  • 1





    Hi. If a question gives a query with a sequence of 8 left joins it is safe to say it should be downvoted & close voted as lacking a Minimal, Complete, and Verifiable example, not answered. Besides, this does not answer the question, it is a tutorial on debugging (which anyway should precede research & entertaining writing a question). Moreover there is no particular reason to expect that the count should stay low as joins are applied, so its approach is flawed.

    – philipxy
    Nov 14 '18 at 22:25













  • clearly one of the tables has 1 to many relationship that is leading to explosion in number of rows returned. All the person who asked the question has to do is above. Because if leave the columns in and now have columns from all 8 different tables; then have to comment each one out. I gave this answer knowing full well user did not supply sample data. Its a path provided to user; if he/she does not want to take it and find answer another way more power to them. ;)

    – junketsu
    Nov 15 '18 at 15:05
















0














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





share|improve this answer



















  • 1





    Hi. If a question gives a query with a sequence of 8 left joins it is safe to say it should be downvoted & close voted as lacking a Minimal, Complete, and Verifiable example, not answered. Besides, this does not answer the question, it is a tutorial on debugging (which anyway should precede research & entertaining writing a question). Moreover there is no particular reason to expect that the count should stay low as joins are applied, so its approach is flawed.

    – philipxy
    Nov 14 '18 at 22:25













  • clearly one of the tables has 1 to many relationship that is leading to explosion in number of rows returned. All the person who asked the question has to do is above. Because if leave the columns in and now have columns from all 8 different tables; then have to comment each one out. I gave this answer knowing full well user did not supply sample data. Its a path provided to user; if he/she does not want to take it and find answer another way more power to them. ;)

    – junketsu
    Nov 15 '18 at 15:05














0












0








0







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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 19:48









junketsujunketsu

34719




34719








  • 1





    Hi. If a question gives a query with a sequence of 8 left joins it is safe to say it should be downvoted & close voted as lacking a Minimal, Complete, and Verifiable example, not answered. Besides, this does not answer the question, it is a tutorial on debugging (which anyway should precede research & entertaining writing a question). Moreover there is no particular reason to expect that the count should stay low as joins are applied, so its approach is flawed.

    – philipxy
    Nov 14 '18 at 22:25













  • clearly one of the tables has 1 to many relationship that is leading to explosion in number of rows returned. All the person who asked the question has to do is above. Because if leave the columns in and now have columns from all 8 different tables; then have to comment each one out. I gave this answer knowing full well user did not supply sample data. Its a path provided to user; if he/she does not want to take it and find answer another way more power to them. ;)

    – junketsu
    Nov 15 '18 at 15:05














  • 1





    Hi. If a question gives a query with a sequence of 8 left joins it is safe to say it should be downvoted & close voted as lacking a Minimal, Complete, and Verifiable example, not answered. Besides, this does not answer the question, it is a tutorial on debugging (which anyway should precede research & entertaining writing a question). Moreover there is no particular reason to expect that the count should stay low as joins are applied, so its approach is flawed.

    – philipxy
    Nov 14 '18 at 22:25













  • clearly one of the tables has 1 to many relationship that is leading to explosion in number of rows returned. All the person who asked the question has to do is above. Because if leave the columns in and now have columns from all 8 different tables; then have to comment each one out. I gave this answer knowing full well user did not supply sample data. Its a path provided to user; if he/she does not want to take it and find answer another way more power to them. ;)

    – junketsu
    Nov 15 '18 at 15:05








1




1





Hi. If a question gives a query with a sequence of 8 left joins it is safe to say it should be downvoted & close voted as lacking a Minimal, Complete, and Verifiable example, not answered. Besides, this does not answer the question, it is a tutorial on debugging (which anyway should precede research & entertaining writing a question). Moreover there is no particular reason to expect that the count should stay low as joins are applied, so its approach is flawed.

– philipxy
Nov 14 '18 at 22:25







Hi. If a question gives a query with a sequence of 8 left joins it is safe to say it should be downvoted & close voted as lacking a Minimal, Complete, and Verifiable example, not answered. Besides, this does not answer the question, it is a tutorial on debugging (which anyway should precede research & entertaining writing a question). Moreover there is no particular reason to expect that the count should stay low as joins are applied, so its approach is flawed.

– philipxy
Nov 14 '18 at 22:25















clearly one of the tables has 1 to many relationship that is leading to explosion in number of rows returned. All the person who asked the question has to do is above. Because if leave the columns in and now have columns from all 8 different tables; then have to comment each one out. I gave this answer knowing full well user did not supply sample data. Its a path provided to user; if he/she does not want to take it and find answer another way more power to them. ;)

– junketsu
Nov 15 '18 at 15:05





clearly one of the tables has 1 to many relationship that is leading to explosion in number of rows returned. All the person who asked the question has to do is above. Because if leave the columns in and now have columns from all 8 different tables; then have to comment each one out. I gave this answer knowing full well user did not supply sample data. Its a path provided to user; if he/she does not want to take it and find answer another way more power to them. ;)

– junketsu
Nov 15 '18 at 15:05




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302866%2fsql-query-doesnt-work-in-my-join-exercises%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues