April 4, 2011 at 1:37 pm
Hello everyone,
I have three tables STUDENT, TERM, GPA
STUDENT
---------
sid | sname | smajor | scat
---------------------------
2 -- sam -- CS -- A
3 -- ram -- EE -- B
9 -- jak -- ME -- B
TERM
-----
tid | sid | tname
---------------------------
1 -- 2 -- SP
2 -- 9 -- S1
3 -- 3 -- S2
4 -- 3 -- FA
1 -- 2 -- SP
GPA
----
tid | gpa | sid
---------------------------
1 -- 3.7 -- 2
3 -- 3.4 -- 3
4 -- 3.3 -- 9
2 -- 3.2 -- 2
Now, I want to update the 'scat' field of 'STUDENT' table to 'A' for all the students whose term related
'gpa' > 3.5. Apparently, I have to do it using 'Joins'. The only part I don't get is updating the 'scat' fields while simultaneously searching for the condition i.e., gpa > 3.5.
Plz Help.
April 4, 2011 at 1:52 pm
This looks like homework, so I'll point you in the right direction is all.
If you're using SQL 2008, as per the forum you posted in, you can use the MERGE command to do this. If you're using an earlier version of SQL Server, you'll need to use UPDATE ... FROM instead.
Can you write a query that selects the person's GPA by joining the tables together? Start from there.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply