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;
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
add a comment |
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
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
add a comment |
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
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
mysql sql
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
Something like that?
SELECT users.id FROM users INNER JOIN teaching on users.id = teaching.userId WHERE teaching.teacherId = '';
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Something like that?
SELECT users.id FROM users INNER JOIN teaching on users.id = teaching.userId WHERE teaching.teacherId = '';
add a comment |
Something like that?
SELECT users.id FROM users INNER JOIN teaching on users.id = teaching.userId WHERE teaching.teacherId = '';
add a comment |
Something like that?
SELECT users.id FROM users INNER JOIN teaching on users.id = teaching.userId WHERE teaching.teacherId = '';
Something like that?
SELECT users.id FROM users INNER JOIN teaching on users.id = teaching.userId WHERE teaching.teacherId = '';
answered Mar 26 at 19:33
Charis MoutafidisCharis Moutafidis
3184 silver badges14 bronze badges
3184 silver badges14 bronze badges
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Mar 26 at 19:32
RisingSunRisingSun
1,22118 silver badges37 bronze badges
1,22118 silver badges37 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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