Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 inner join distinct

Author  Topic 

arusu
Yak Posting Veteran

60 Posts

Posted - 2010-08-24 : 15:02:39
hi, i have a select statement that selects an employee and there is an employee id that links to a job table. so i need

select e.name, e.address
inner join job j on e.equipment_id = j.equipment_id

but an employee can have multiple jobs but i don't want it to return more rows because of multiple jobs.

hope i explained it ok but....

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-24 : 15:04:05
Which job do you want it to return if there are multiples?

Could you show us some sample data?

You'll likely need to use the ROW_NUMBER() function (2005+) or GROUP BY/MAX/derived table (2000).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

arusu
Yak Posting Veteran

60 Posts

Posted - 2010-08-24 : 15:12:48
ok to give a little more detail this employee table is linked with a company table so a company can have the same employee as another company and each employee has a performance table so when you look at everything in a view, it could be like this

company employee performance
A jack good
B jack poor

and basically i want to use the job as a user filter. So a user can select a job and display everyone based on a job and some other filters which are not important. But when i inner join the job table, i get more performance results and i shouldn't

not sure if that makes more sense but that's what i need
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-08-24 : 16:09:51
quote:
Originally posted by arusu

<snip>
not sure if that makes more sense but that's what i need

Not really. We'd love to help you, but what you ahve posted doesn't really make much sense. Additionally, we have no idea what tables you have or how they relate to each other. This link might help you with posting your question so we can help you better:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-25 : 09:27:32
quote:
Originally posted by arusu

ok to give a little more detail this employee table is linked with a company table so a company can have the same employee as another company and each employee has a performance table so when you look at everything in a view, it could be like this

company employee performance
A jack good
B jack poor

and basically i want to use the job as a user filter. So a user can select a job and display everyone based on a job and some other filters which are not important. But when i inner join the job table, i get more performance results and i shouldn't

not sure if that makes more sense but that's what i need


then you need to have a field (may be an id) which determines which employee belongs to which company (may be names are same but id will be different)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -