Hi all,
I'm new here and this is my 2nd post. I already got tremendous help and hope someone can help me as I learn sql (took mysql two years ago). I am REALLY rusty, so I appreciate any tips/help.
Database 1:
table 1. Contains ssn, id.
Database 2:
table 2. Contains ssn, id, last_name, first_name.
So, here's what I need to do. I need to search in db1.dbo.table1 for id = 0; this is how I do it:
select x.ssn from db1.dbo.table1 x
where x.emplid = '0'
order by s.ssn asc
Now... I have all the SSN's where id = 0. However, I want to display the results by last_name and first_name, not SSN. To retrieve the names, I have to search table 2, db2.
I'm really stuck here and as far as I know, this is probably pretty easy to do. Is there a way I can store the ssn's I pull from the first table, then do something like this:
select y.last_name, y.first_name
from database2.dbo.table2 y
where stored_ssn = y.ssn
given that stored_ssn is a variable that stores all the ssn query results from table 1.
I hope this doesn't sound overly complicated. I need to pull the names from table 2 based on the ssn I have pulled from table 1.
TIA.
I'm new here and this is my 2nd post. I already got tremendous help and hope someone can help me as I learn sql (took mysql two years ago). I am REALLY rusty, so I appreciate any tips/help.
Database 1:
table 1. Contains ssn, id.
Database 2:
table 2. Contains ssn, id, last_name, first_name.
So, here's what I need to do. I need to search in db1.dbo.table1 for id = 0; this is how I do it:
select x.ssn from db1.dbo.table1 x
where x.emplid = '0'
order by s.ssn asc
Now... I have all the SSN's where id = 0. However, I want to display the results by last_name and first_name, not SSN. To retrieve the names, I have to search table 2, db2.
I'm really stuck here and as far as I know, this is probably pretty easy to do. Is there a way I can store the ssn's I pull from the first table, then do something like this:
select y.last_name, y.first_name
from database2.dbo.table2 y
where stored_ssn = y.ssn
given that stored_ssn is a variable that stores all the ssn query results from table 1.
I hope this doesn't sound overly complicated. I need to pull the names from table 2 based on the ssn I have pulled from table 1.
TIA.