Yii2 - Syntax error or access violation: 1066 Not unique table












-1














I'm trying to join two tables in a query :






- sc_cours -
idCour
volHoraireCour
idMat

- sc_matieres -
idMat
nomMat





the code of the query is the following






$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat');





But i get this following error






SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'sc_matieres' non unique
The SQL being executed was: SELECT * FROM `sc_cours` INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat





Do you know what's the main problem guys? Thanks you!










share|improve this question






















  • Try this - $query = new yiidbQuery(); $query->select(['a.*','b.*']) ->from(['a' => 'sc_cours']) ->innerJoin(['b' => 'sc_matieres'],'a.idMat = b.idMat') ->all();
    – Gru
    Nov 21 at 4:54












  • I have the same error, but this time on the aliases Syntax error or access violation: 1066 Table/alias: 'b' non unique The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN sc_matieres b ON a.idMat = b.idMat INNER JOIN sc_matieres b ON a.idMat = b.idMat
    – Badara
    Nov 21 at 13:43


















-1














I'm trying to join two tables in a query :






- sc_cours -
idCour
volHoraireCour
idMat

- sc_matieres -
idMat
nomMat





the code of the query is the following






$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat');





But i get this following error






SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'sc_matieres' non unique
The SQL being executed was: SELECT * FROM `sc_cours` INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat





Do you know what's the main problem guys? Thanks you!










share|improve this question






















  • Try this - $query = new yiidbQuery(); $query->select(['a.*','b.*']) ->from(['a' => 'sc_cours']) ->innerJoin(['b' => 'sc_matieres'],'a.idMat = b.idMat') ->all();
    – Gru
    Nov 21 at 4:54












  • I have the same error, but this time on the aliases Syntax error or access violation: 1066 Table/alias: 'b' non unique The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN sc_matieres b ON a.idMat = b.idMat INNER JOIN sc_matieres b ON a.idMat = b.idMat
    – Badara
    Nov 21 at 13:43
















-1












-1








-1







I'm trying to join two tables in a query :






- sc_cours -
idCour
volHoraireCour
idMat

- sc_matieres -
idMat
nomMat





the code of the query is the following






$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat');





But i get this following error






SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'sc_matieres' non unique
The SQL being executed was: SELECT * FROM `sc_cours` INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat





Do you know what's the main problem guys? Thanks you!










share|improve this question













I'm trying to join two tables in a query :






- sc_cours -
idCour
volHoraireCour
idMat

- sc_matieres -
idMat
nomMat





the code of the query is the following






$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat');





But i get this following error






SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'sc_matieres' non unique
The SQL being executed was: SELECT * FROM `sc_cours` INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat





Do you know what's the main problem guys? Thanks you!






- sc_cours -
idCour
volHoraireCour
idMat

- sc_matieres -
idMat
nomMat





- sc_cours -
idCour
volHoraireCour
idMat

- sc_matieres -
idMat
nomMat





$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat');





$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat');





SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'sc_matieres' non unique
The SQL being executed was: SELECT * FROM `sc_cours` INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat





SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'sc_matieres' non unique
The SQL being executed was: SELECT * FROM `sc_cours` INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat






yii2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 2:47









Badara

11




11












  • Try this - $query = new yiidbQuery(); $query->select(['a.*','b.*']) ->from(['a' => 'sc_cours']) ->innerJoin(['b' => 'sc_matieres'],'a.idMat = b.idMat') ->all();
    – Gru
    Nov 21 at 4:54












  • I have the same error, but this time on the aliases Syntax error or access violation: 1066 Table/alias: 'b' non unique The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN sc_matieres b ON a.idMat = b.idMat INNER JOIN sc_matieres b ON a.idMat = b.idMat
    – Badara
    Nov 21 at 13:43




















  • Try this - $query = new yiidbQuery(); $query->select(['a.*','b.*']) ->from(['a' => 'sc_cours']) ->innerJoin(['b' => 'sc_matieres'],'a.idMat = b.idMat') ->all();
    – Gru
    Nov 21 at 4:54












  • I have the same error, but this time on the aliases Syntax error or access violation: 1066 Table/alias: 'b' non unique The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN sc_matieres b ON a.idMat = b.idMat INNER JOIN sc_matieres b ON a.idMat = b.idMat
    – Badara
    Nov 21 at 13:43


















Try this - $query = new yiidbQuery(); $query->select(['a.*','b.*']) ->from(['a' => 'sc_cours']) ->innerJoin(['b' => 'sc_matieres'],'a.idMat = b.idMat') ->all();
– Gru
Nov 21 at 4:54






Try this - $query = new yiidbQuery(); $query->select(['a.*','b.*']) ->from(['a' => 'sc_cours']) ->innerJoin(['b' => 'sc_matieres'],'a.idMat = b.idMat') ->all();
– Gru
Nov 21 at 4:54














I have the same error, but this time on the aliases Syntax error or access violation: 1066 Table/alias: 'b' non unique The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN sc_matieres b ON a.idMat = b.idMat INNER JOIN sc_matieres b ON a.idMat = b.idMat
– Badara
Nov 21 at 13:43






I have the same error, but this time on the aliases Syntax error or access violation: 1066 Table/alias: 'b' non unique The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN sc_matieres b ON a.idMat = b.idMat INNER JOIN sc_matieres b ON a.idMat = b.idMat
– Badara
Nov 21 at 13:43














2 Answers
2






active

oldest

votes


















0














From error you can see that you have two inner joins exact same. Define relation in model and than just do ->innerJoin('nameOfRelation');






share|improve this answer





















  • There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
    – Badara
    Nov 21 at 23:53












  • why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
    – Borisa Eric
    Nov 22 at 9:56










  • sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
    – Badara
    Nov 22 at 11:49












  • No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
    – Borisa Eric
    Nov 22 at 13:17










  • ok i've posted all the code
    – Badara
    Nov 22 at 15:15





















0














Ok, with ->ScCours::find()->join('mat') I've this error Missing argument 2 for yiidbQuery::join() , But Thank you, you put me on the right path because it works when i try with with , so i've just done ->ScCours::find()->with('mat'). That's worked now, thank you again Borisa Eric for your precious help !






share|improve this answer





















    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%2f53404609%2fyii2-syntax-error-or-access-violation-1066-not-unique-table%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    From error you can see that you have two inner joins exact same. Define relation in model and than just do ->innerJoin('nameOfRelation');






    share|improve this answer





















    • There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
      – Badara
      Nov 21 at 23:53












    • why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
      – Borisa Eric
      Nov 22 at 9:56










    • sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
      – Badara
      Nov 22 at 11:49












    • No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
      – Borisa Eric
      Nov 22 at 13:17










    • ok i've posted all the code
      – Badara
      Nov 22 at 15:15


















    0














    From error you can see that you have two inner joins exact same. Define relation in model and than just do ->innerJoin('nameOfRelation');






    share|improve this answer





















    • There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
      – Badara
      Nov 21 at 23:53












    • why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
      – Borisa Eric
      Nov 22 at 9:56










    • sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
      – Badara
      Nov 22 at 11:49












    • No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
      – Borisa Eric
      Nov 22 at 13:17










    • ok i've posted all the code
      – Badara
      Nov 22 at 15:15
















    0












    0








    0






    From error you can see that you have two inner joins exact same. Define relation in model and than just do ->innerJoin('nameOfRelation');






    share|improve this answer












    From error you can see that you have two inner joins exact same. Define relation in model and than just do ->innerJoin('nameOfRelation');







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 21 at 16:50









    Borisa Eric

    29916




    29916












    • There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
      – Badara
      Nov 21 at 23:53












    • why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
      – Borisa Eric
      Nov 22 at 9:56










    • sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
      – Badara
      Nov 22 at 11:49












    • No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
      – Borisa Eric
      Nov 22 at 13:17










    • ok i've posted all the code
      – Badara
      Nov 22 at 15:15




















    • There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
      – Badara
      Nov 21 at 23:53












    • why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
      – Borisa Eric
      Nov 22 at 9:56










    • sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
      – Badara
      Nov 22 at 11:49












    • No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
      – Borisa Eric
      Nov 22 at 13:17










    • ok i've posted all the code
      – Badara
      Nov 22 at 15:15


















    There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
    – Badara
    Nov 21 at 23:53






    There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
    – Badara
    Nov 21 at 23:53














    why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
    – Borisa Eric
    Nov 22 at 9:56




    why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
    – Borisa Eric
    Nov 22 at 9:56












    sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
    – Badara
    Nov 22 at 11:49






    sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
    – Badara
    Nov 22 at 11:49














    No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
    – Borisa Eric
    Nov 22 at 13:17




    No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
    – Borisa Eric
    Nov 22 at 13:17












    ok i've posted all the code
    – Badara
    Nov 22 at 15:15






    ok i've posted all the code
    – Badara
    Nov 22 at 15:15















    0














    Ok, with ->ScCours::find()->join('mat') I've this error Missing argument 2 for yiidbQuery::join() , But Thank you, you put me on the right path because it works when i try with with , so i've just done ->ScCours::find()->with('mat'). That's worked now, thank you again Borisa Eric for your precious help !






    share|improve this answer


























      0














      Ok, with ->ScCours::find()->join('mat') I've this error Missing argument 2 for yiidbQuery::join() , But Thank you, you put me on the right path because it works when i try with with , so i've just done ->ScCours::find()->with('mat'). That's worked now, thank you again Borisa Eric for your precious help !






      share|improve this answer
























        0












        0








        0






        Ok, with ->ScCours::find()->join('mat') I've this error Missing argument 2 for yiidbQuery::join() , But Thank you, you put me on the right path because it works when i try with with , so i've just done ->ScCours::find()->with('mat'). That's worked now, thank you again Borisa Eric for your precious help !






        share|improve this answer












        Ok, with ->ScCours::find()->join('mat') I've this error Missing argument 2 for yiidbQuery::join() , But Thank you, you put me on the right path because it works when i try with with , so i've just done ->ScCours::find()->with('mat'). That's worked now, thank you again Borisa Eric for your precious help !







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 at 19:21









        Badara

        11




        11






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53404609%2fyii2-syntax-error-or-access-violation-1066-not-unique-table%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

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'