Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
tats
Starting Member
5 Posts |
Posted - 2014-12-11 : 15:31:37
|
Hi all,I would appreciate a help with this exercise:"For every situation where student A likes student B, but we have no information about whom B likes (that is, B does not appear as an ID1 in the Likes table), return A and B's names and grades".My question is what is the way to find B in ID1 in Likes table? The script that I have written and that gives empty results is:(Notes: In Highschooler table one finds - student ID, Name, GradeIn Likes table one finds - ID1, ID2 (of students who mutually or onesidedly like each other))Select H1.name, H1.grade, H2.name, H2.gradeFrom Highschooler H1 inner join Highschooler H2 using(ID)inner join(select L1.ID1, L2.ID2From Likes L1 inner join Likes L2 on L1.ID1 = L2.ID1 and L1.ID2 = L2.ID2Where L1.ID2 not in(select L1.ID1From Likes L1 inner join Likes L2 on L1.ID1 = L2.ID1 and L1.ID2 = L2.ID2) on ID = ID1)Thanks a lot for any hints/help!! |
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2014-12-11 : 20:20:36
|
Can we see the table schema? Referential integrity? Data? No amount of belief makes something a fact. -James Randi |
|
|
tats
Starting Member
5 Posts |
Posted - 2014-12-12 : 04:42:55
|
Hi,Here are the two tables below. Many thanks in advance for a help!HighschoolerID name grade1510 Jordan 91689 Gabriel 91381 Tiffany 91709 Cassandra 91101 Haley 101782 Andrew 101468 Kris 101641 Brittany 101247 Alexis 111316 Austin 111911 Gabriel 111501 Jessica 111304 Jordan 121025 John 121934 Kyle 121661 Logan 12LikesID1 ID21689 17091709 16891782 17091911 12471247 14681641 14681316 13041501 19341934 15011025 1101 |
|
|
tats
Starting Member
5 Posts |
Posted - 2014-12-12 : 06:30:03
|
I have solved this, please, never mind :) |
|
|
tats
Starting Member
5 Posts |
Posted - 2014-12-12 : 06:40:14
|
I have another question though, is someone could help.I have created this table of paired students: ID1, name1, grade1, ID2, Name2, grade2Select distinct F1.ID1, H1.name, H1.Grade, F2.ID2, H2.name, H2.GradeFrom Friend F1 inner join Highschooler H1 on F1.ID1 = H1.IDInner join Friend F2 on F1.ID2 = F2.ID2Inner join Highschooler H2 on H2.ID = F2.ID2From here I need to select the students who has a pair only in the same grade (If a student has a pair in another grade at the same time, I should exclude him/her). Any suggestions how can I do that?1025 John 12 1661 Logan 121101 Haley 10 1468 Kris 101101 Haley 10 1641 Brittany 101247 Alexis 11 1381 Tiffany 91247 Alexis 11 1501 Jessica 111247 Alexis 11 1709 Cassandra 91247 Alexis 11 1911 Gabriel 111304 Jordan 12 1661 Logan 121304 Jordan 12 1782 Andrew 101304 Jordan 12 1934 Kyle 121316 Austin 11 1782 Andrew 101316 Austin 11 1934 Kyle 12 |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-12-12 : 08:53:26
|
Please stop posting your homework. if you need help, ask your instructor or their assistant |
|
|
tats
Starting Member
5 Posts |
Posted - 2014-12-12 : 09:10:46
|
well, I am just doing an online course, where unfortunately there is no instructor to help with questions. I was sure forums are to discuss and get help with issues that one does not know. Probably I am not in the right forum, there will be no other posts.On the last note, I solved also this exercise. |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2014-12-12 : 11:20:05
|
It does seem that you are fully capable of deriving the solutions on your own. So far you are two for two. No amount of belief makes something a fact. -James Randi |
|
|
|
|
|
|
|