Get one row from table based off anothermySQL join same table twiceBest way to get identity of inserted row?How to concatenate text from multiple rows into a single text string in SQL server?Get list of all tables in Oracle?SQL update from one Table to another based on a ID matchSetting up foreign keys in phpMyAdmin?MySQL - UPDATE query based on SELECT QuerySQL Server: How to Join to first rowHow to get the sizes of the tables of a MySQL database?SQL Inner-join with 3 tables?MySQL replace foreign key in result table with data from FK table

How did the SysRq key get onto modern keyboards if it's rarely used?

When I cite content from a book, should I say "section 2.3.2.1 of book... " or "section 2.3.2.1 of `the` book ..."?

Did the Americans trade destroyers in the "destroyer deal" that they would later need themselves?

Must a song using the A minor scale begin or end with an Am chord? If not, how can I tell what the scale is?

Why not notify faculty candidates of the position being filled?

What is "aligned sequences" and "consensus sequence" in the context of sequence logo? How to compute these?

How to find the mass density function of a solid given its total mass, its volume and the position of its center of mass?

Why did House of Representatives need to condemn Trumps Tweets?

Irreducible factors of primitive permutation group representation

What do I do with a party that is much stronger than their level?

World of (nearly) identical snowflakes

What are the closest international airports in different countries?

Composing fill in the blanks

How do you pronounce "Hain"?

Why would anyone ever invest in a cash-only etf?

Why force the nose of 737 Max down in the first place?

Wand of the War Mage spellcasting focus and bonus interaction with multiclassing

If Trump gets impeached, how long would Pence be president?

Why do they sell Cat 5 Ethernet splitters if you can’t split the signal?

Assuring luggage isn't lost with short layover

Finding the Maximum of a Continuous Function over a Closed Interval

Can an Oathbreaker Paladin reform and choose a different Paladin subclass?

Increasing labelling size in a ListPointPlot3D

What do you call a flexible diving platform?



Get one row from table based off another


mySQL join same table twiceBest way to get identity of inserted row?How to concatenate text from multiple rows into a single text string in SQL server?Get list of all tables in Oracle?SQL update from one Table to another based on a ID matchSetting up foreign keys in phpMyAdmin?MySQL - UPDATE query based on SELECT QuerySQL Server: How to Join to first rowHow to get the sizes of the tables of a MySQL database?SQL Inner-join with 3 tables?MySQL replace foreign key in result table with data from FK table






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have two tables, users and teaching



The users table contains both teachers and students. The teaching table contains the relation between the two.



I want to be able to get the student based off who "teaches" them.



Both teachers and students have an id, and I would have the teachers id to look up in the teaching table to find the students they teach.



Any ideas as to how this is done? I would like it to return the id of the student.



I've tried doing a simple join statement, but this would fetch the teacher, not the student.



Thanks in advance










share|improve this question


























  • Possible duplicate of mySQL join same table twice

    – RisingSun
    Mar 26 at 19:37






  • 1





    Sample data and desired results would really help.

    – Gordon Linoff
    Mar 26 at 19:38

















1















I have two tables, users and teaching



The users table contains both teachers and students. The teaching table contains the relation between the two.



I want to be able to get the student based off who "teaches" them.



Both teachers and students have an id, and I would have the teachers id to look up in the teaching table to find the students they teach.



Any ideas as to how this is done? I would like it to return the id of the student.



I've tried doing a simple join statement, but this would fetch the teacher, not the student.



Thanks in advance










share|improve this question


























  • Possible duplicate of mySQL join same table twice

    – RisingSun
    Mar 26 at 19:37






  • 1





    Sample data and desired results would really help.

    – Gordon Linoff
    Mar 26 at 19:38













1












1








1








I have two tables, users and teaching



The users table contains both teachers and students. The teaching table contains the relation between the two.



I want to be able to get the student based off who "teaches" them.



Both teachers and students have an id, and I would have the teachers id to look up in the teaching table to find the students they teach.



Any ideas as to how this is done? I would like it to return the id of the student.



I've tried doing a simple join statement, but this would fetch the teacher, not the student.



Thanks in advance










share|improve this question
















I have two tables, users and teaching



The users table contains both teachers and students. The teaching table contains the relation between the two.



I want to be able to get the student based off who "teaches" them.



Both teachers and students have an id, and I would have the teachers id to look up in the teaching table to find the students they teach.



Any ideas as to how this is done? I would like it to return the id of the student.



I've tried doing a simple join statement, but this would fetch the teacher, not the student.



Thanks in advance







mysql sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Dharman

7,4159 gold badges29 silver badges63 bronze badges




7,4159 gold badges29 silver badges63 bronze badges










asked Mar 26 at 19:30







user10976392






















  • Possible duplicate of mySQL join same table twice

    – RisingSun
    Mar 26 at 19:37






  • 1





    Sample data and desired results would really help.

    – Gordon Linoff
    Mar 26 at 19:38

















  • Possible duplicate of mySQL join same table twice

    – RisingSun
    Mar 26 at 19:37






  • 1





    Sample data and desired results would really help.

    – Gordon Linoff
    Mar 26 at 19:38
















Possible duplicate of mySQL join same table twice

– RisingSun
Mar 26 at 19:37





Possible duplicate of mySQL join same table twice

– RisingSun
Mar 26 at 19:37




1




1





Sample data and desired results would really help.

– Gordon Linoff
Mar 26 at 19:38





Sample data and desired results would really help.

– Gordon Linoff
Mar 26 at 19:38












2 Answers
2






active

oldest

votes


















0














Something like that?



SELECT users.id FROM users INNER JOIN teaching on users.id = teaching.userId WHERE teaching.teacherId = '';





share|improve this answer
































    0














    You just need to join the users table again to the teaching table. Just make sure in one join you are using the teachers' ids and in the other the students' ids.



    You can join the same table multiple times and that is totally legal in MySQL






    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%2f55364934%2fget-one-row-from-table-based-off-another%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














      Something like that?



      SELECT users.id FROM users INNER JOIN teaching on users.id = teaching.userId WHERE teaching.teacherId = '';





      share|improve this answer





























        0














        Something like that?



        SELECT users.id FROM users INNER JOIN teaching on users.id = teaching.userId WHERE teaching.teacherId = '';





        share|improve this answer



























          0












          0








          0







          Something like that?



          SELECT users.id FROM users INNER JOIN teaching on users.id = teaching.userId WHERE teaching.teacherId = '';





          share|improve this answer













          Something like that?



          SELECT users.id FROM users INNER JOIN teaching on users.id = teaching.userId WHERE teaching.teacherId = '';






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 26 at 19:33









          Charis MoutafidisCharis Moutafidis

          3184 silver badges14 bronze badges




          3184 silver badges14 bronze badges


























              0














              You just need to join the users table again to the teaching table. Just make sure in one join you are using the teachers' ids and in the other the students' ids.



              You can join the same table multiple times and that is totally legal in MySQL






              share|improve this answer





























                0














                You just need to join the users table again to the teaching table. Just make sure in one join you are using the teachers' ids and in the other the students' ids.



                You can join the same table multiple times and that is totally legal in MySQL






                share|improve this answer



























                  0












                  0








                  0







                  You just need to join the users table again to the teaching table. Just make sure in one join you are using the teachers' ids and in the other the students' ids.



                  You can join the same table multiple times and that is totally legal in MySQL






                  share|improve this answer













                  You just need to join the users table again to the teaching table. Just make sure in one join you are using the teachers' ids and in the other the students' ids.



                  You can join the same table multiple times and that is totally legal in MySQL







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 26 at 19:32









                  RisingSunRisingSun

                  1,22118 silver badges37 bronze badges




                  1,22118 silver badges37 bronze badges






























                      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%2f55364934%2fget-one-row-from-table-based-off-another%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

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현