question

coljen avatar image
coljen asked

Subqueries

Using TSQL Fundamentals 2008 database how can I: List empid, lastname, firstname of all employees who are managers. Using a subquery
sql-server-2008homework
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

WilliamD avatar image
WilliamD answered
1. select all the employee Ids that are managers in the sub-query 2. select all columns you need from employees and reference to the sub-query on empid Just a quick note to this question. I guess that this is homework, if I am wrong please let me know. As such, let me say, it would be better if you supply us with what code you have so far and we can give pointers on how to change/improve the code. This is also valid even if it is not homework - give us what you have so far, we aren't really here to provide a complete solution (rather help out where you are stuck). Back to the question - I don't think a subquery would even be necessary - although I don't have the table structure or example data (provide this in future for a little more detailed help from others).
7 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image Kev Riley ♦♦ commented ·
+1 definitely homework - ever seen a business requirement that states 'must use subquery'??
1 Like 1 ·
Scot Hauder avatar image Scot Hauder commented ·
@William/Kev You've seen a requirement spec!?
1 Like 1 ·
WilliamD avatar image WilliamD commented ·
depends on the requestor - previous job had people with dangerous half-knowledge and sprinkled that sort of thing into the requirement spec. Tell me what you want, not how you want it doing!
0 Likes 0 ·
Kev Riley avatar image Kev Riley ♦♦ commented ·
glad it's a previous job and not a current one!
0 Likes 0 ·
WilliamD avatar image WilliamD commented ·
..........
0 Likes 0 ·
David Wimbush avatar image David Wimbush commented ·
@Scott: He did say it was a previous job. I doubt that sort of thing happens these days!
0 Likes 0 ·
WilliamD avatar image WilliamD commented ·
@David - see also my comment above Scot's. If life were only so good.
0 Likes 0 ·
Fatherjack avatar image
Fatherjack answered
Taking the question that you have asked you need to SELECT some data from a table WHERE certain values meet some criteria. My suggestion would be to start by just getting all the data from the table you are working with a then, once you can see all of that reduce the columns that you want to have and add a filter to remove rows where the record doesnt relate to a manager. As some reference I would recommend [ http://msdn.microsoft.com/en-US/library/ms189499(v=SQL.90).aspx][1] as your starting point. Just a quick note on the fact that this might be a college/homework question. We do not by any means disapprove or discourage students asking questions here. We will simply tailor our advice to help you understand what you are being asked to provide and how you might achieve that. Thanks for asking your question here. Let us know how you get on and if you have more question please come back to ask them. And dont be shy to let us know if you are a student [1]: http://msdn.microsoft.com/en-US/library/ms189499(v=SQL.90).aspx
4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

WilliamD avatar image WilliamD commented ·
+1 for the clarification that being a student and posting hoemwork is not a bad thing (i may have sounded a little harsh).
1 Like 1 ·
Fatherjack avatar image Fatherjack ♦♦ commented ·
I dont think you were at all harsh William, I just think its a good thing to have students using the site and would like to encourage them. After all, if they succeed on their course they may become DBAs that will continue visiting and in turn help other (students) here.
1 Like 1 ·
Kev Riley avatar image Kev Riley ♦♦ commented ·
@WilliamD : we discussed what to do with homework questions a while back - like Fatherjack says, we don't mind them, we would just rather know if they are homework or not, then we can offer the right kind of answer
0 Likes 0 ·
WilliamD avatar image WilliamD commented ·
@Kev - ta very much - so it is pretty much as I see it then. Help, but the poster has to put some effort in first.
0 Likes 0 ·
coljen avatar image
coljen answered
This is not part of any homework question
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.