Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Query to return 2 different names in same record

 
   Database Help (Home) -> MSEQ RSS
Next:  implode or what?  
Author Message
PeterW

External


Since: Oct 04, 2008
Posts: 3



(Msg. 1) Posted: Sat Oct 04, 2008 3:15 am
Post subject: Query to return 2 different names in same record
Archived from groups: microsoft>public>sqlserver>mseq (more info?)

I am trying to build a database to keep a record of skills held by employees
in our company. I have 3 tables Employee, Employee Skills, and Skills.
In the employee skills table I want the name of the employee and the name of
the assessor who tested the skill. Both these names are in the employee
table. In the Employee Skills table I have 2 foreign keys to the EmpID in the
Employees table, one of EmpID for the employee name and another of
AssesorEmpID to record the name of the assesor.
I want to return the name of the employee and the name of the assesor in a
query to show the employees skill level and who approved it. I know I could
use a look up and store the actual name of the assessor but was hoping to
keep things clean by using just the EmpID and AssesorEmpID from the employees
table.
Is this possible?

 >> Stay informed about: Query to return 2 different names in same record 
Back to top
Login to vote
Hugo Kornelis

External


Since: Jan 11, 2008
Posts: 440



(Msg. 2) Posted: Sat Oct 04, 2008 6:26 pm
Post subject: Re: Query to return 2 different names in same record [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Sat, 4 Oct 2008 03:15:01 -0700, PeterW wrote:

>I am trying to build a database to keep a record of skills held by employees
>in our company. I have 3 tables Employee, Employee Skills, and Skills.
>In the employee skills table I want the name of the employee and the name of
>the assessor who tested the skill. Both these names are in the employee
>table. In the Employee Skills table I have 2 foreign keys to the EmpID in the
>Employees table, one of EmpID for the employee name and another of
>AssesorEmpID to record the name of the assesor.
>I want to return the name of the employee and the name of the assesor in a
>query to show the employees skill level and who approved it. I know I could
>use a look up and store the actual name of the assessor but was hoping to
>keep things clean by using just the EmpID and AssesorEmpID from the employees
>table.
>Is this possible?

Hi Peter,

Yes, it is.

SELECT e.EmpName AS Employee,
a.EmpName AS Assesor,
s.SkillName AS Skill
FROM EmployeeSkills AS es
INNER JOIN Employee AS e
ON e.EmpID = es.EmpID
INNER JOIN Employee AS a
ON a.EmpID = es.AssesorEmpID
INNER JOIN Skills AS s
ON s.SkillID = es.SkillID;

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

 >> Stay informed about: Query to return 2 different names in same record 
Back to top
Login to vote
PeterW

External


Since: Oct 04, 2008
Posts: 3



(Msg. 3) Posted: Sun Oct 05, 2008 2:31 am
Post subject: Re: Query to return 2 different names in same record [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks you're a gent.
Does this stop the orderby, groupby, or where clause from working?

"Hugo Kornelis" wrote:

> On Sat, 4 Oct 2008 03:15:01 -0700, PeterW wrote:
>
> >I am trying to build a database to keep a record of skills held by employees
> >in our company. I have 3 tables Employee, Employee Skills, and Skills.
> >In the employee skills table I want the name of the employee and the name of
> >the assessor who tested the skill. Both these names are in the employee
> >table. In the Employee Skills table I have 2 foreign keys to the EmpID in the
> >Employees table, one of EmpID for the employee name and another of
> >AssesorEmpID to record the name of the assesor.
> >I want to return the name of the employee and the name of the assesor in a
> >query to show the employees skill level and who approved it. I know I could
> >use a look up and store the actual name of the assessor but was hoping to
> >keep things clean by using just the EmpID and AssesorEmpID from the employees
> >table.
> >Is this possible?
>
> Hi Peter,
>
> Yes, it is.
>
> SELECT e.EmpName AS Employee,
> a.EmpName AS Assesor,
> s.SkillName AS Skill
> FROM EmployeeSkills AS es
> INNER JOIN Employee AS e
> ON e.EmpID = es.EmpID
> INNER JOIN Employee AS a
> ON a.EmpID = es.AssesorEmpID
> INNER JOIN Skills AS s
> ON s.SkillID = es.SkillID;
>
> --
> Hugo Kornelis, SQL Server MVP
> My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
>
 >> Stay informed about: Query to return 2 different names in same record 
Back to top
Login to vote
Hugo Kornelis

External


Since: Jan 11, 2008
Posts: 440



(Msg. 4) Posted: Sun Oct 05, 2008 5:25 pm
Post subject: Re: Query to return 2 different names in same record [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Sun, 5 Oct 2008 02:31:01 -0700, PeterW wrote:

>Thanks you're a gent.
>Does this stop the orderby, groupby, or where clause from working?

Hi Peter,

No. But you do need to keep using the aliases instead of the table names
whenever you refer to columns from the tables.

(Note that an alias is not required -though I presonally prefer it- for
tables that appear just once in a query - but tables appearing twice or
more do need an alias to seperate the "versions").

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
 >> Stay informed about: Query to return 2 different names in same record 
Back to top
Login to vote
PeterW

External


Since: Oct 04, 2008
Posts: 3



(Msg. 5) Posted: Mon Oct 06, 2008 12:54 am
Post subject: Re: Query to return 2 different names in same record [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks again you have been a great help

"Hugo Kornelis" wrote:

> On Sun, 5 Oct 2008 02:31:01 -0700, PeterW wrote:
>
> >Thanks you're a gent.
> >Does this stop the orderby, groupby, or where clause from working?
>
> Hi Peter,
>
> No. But you do need to keep using the aliases instead of the table names
> whenever you refer to columns from the tables.
>
> (Note that an alias is not required -though I presonally prefer it- for
> tables that appear just once in a query - but tables appearing twice or
> more do need an alias to seperate the "versions").
>
> --
> Hugo Kornelis, SQL Server MVP
> My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
>
 >> Stay informed about: Query to return 2 different names in same record 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
query assistance -return most recent date - I have a table that has two fields, pkg_num, which is a number, and del_date_time, which is a date-time. The table can contain duplicate pkg_num values, as long as the del_date_time values are different for any given number. I need a query that will...

Extracting the table names to which a fied is related to - I am using a database with n tables in it. I have a set of field names with me. what I want is to find the names of the tables in which a particular field is mapped to or related to in order to find the effect of a particular field to the database. ..

Running a Update query based on information from Insert Qu.. - I am trying to setup a script where I run an insert query to insert information into a table. The first part I have down pat as far as the Insert, where I'm having difficulties is that the information is coming from an outside source and the input..

Simple Query problem - Sample table as follows Order ID Stock Code Status --------- ------- ------- 203 STK1 3 203 STK2 2 203 STK4 3 204 STK1 3 204 STK5 3 205 ..

Hopefully a basic query question - Good afternoon, I am trying to create a query. Underlying data in table is: Job No/Cost Type/$ J8000/1/3000 J8000/2/2000 J8000/2/5000 J8000/2/1000 In the above a Cost type of 1 equates to Labour cost, and a Cost type of 2 equates to Materials cost....
   Database Help (Home) -> MSEQ All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]