I'm in the process of learning SQL Server, and so I'm not quite sure what the proper terms to search for something like this are.
I have two tables, People (ID, FirstName, LastName, Job):
ID FirstName LastName Job
1 Barack Obama Null // Obama is unemployed
and Companies (ID, CompanyName, City, State):
ID CompanyName City State
1 Legislative Branch Washington DC
2 Executive Branch Washington DC
3 Judicial Branch Washington DC
I know I can run something like
update Persons
set Job = '2'
where ID = 1;
to do that manually, but that requires me to know that Executive Branch's ID is 2.
How would I write a query that looks up CompanyName == 'Executive Branch' in the Companies table then uses the ID from there?
ID FirstName LastName Job
----------------------------------
1 Barack Obama 2 //Obama now works for the Executive Branch
Possibly related, is it considered "bad form" to use ID for both of those tables, or should one be PersonID and the other CompanyID?
Thanks!
Jobcolumn. So, theIDfromPeopleshould be the same as theIDin companies?, and then you want to update that very sameIDto theJobcolumn?