Suppose I have a SQL query that looks like this:
SELECT fName from employees where ssn=123456789;
Suppose I want to follow the previous query with another one:
SELECT fName from records WHERE ssn=123456789;
SELECT lName from records WHERE fName=(the result of the previous query)
What do I put in for (the result of the previous query) to make this return the last names from records where the fName matches the presumably unique record where ssn=123456789?
I know that this is an unrealistic example, but what I’m asking is, “How do I refer to the result of my previous query?”
BTW, if it makes any difference, I’m using MS SQL Server 2008. Thanks!
You can save the result of the first query into a variable and use that variable in the second query.