?
Solved

join on multiple tables

Posted on 2009-07-06
4
Medium Priority
?
663 Views
Last Modified: 2013-11-11
I have the following two tables in a SQL 2005 database.

people
--------
person_id (PK)
first_name
mid_name
last_name
empl_id

multiple_sources
----------
source
person_id (This is a FK to people.person_id)


Here is what I want to accomplish;
Write a script (using C# and LINQ) to identify all the records in the people table having the same empl_id - basically a "group by on empl_id having count(empl_id) > 1". The output needs to contain all the columns in the people table. Now, I also need to (left) join the people table with the multiple_sources table and exclude all the person_id's that have multiple_sources.source of either a "D" or a "Z".

I want to schedule to script to run once a week and forward the output to a group of people in my organization for data cleanup.

Can someone please help me get started?
Thank you.
0
Comment
Question by:IUAATech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 24790860
Hi IUAATech;

The following query will locate all people with the same empl_id and that the group is greater then 1.

Fernando
DataClasses1DataContext db = new DataClasses1DataContext();
 
var results = from p in db.peoples
              group p by p.empl_id into emplGroup
              where emplGroup.Count() > 1
              from g in emplGroup
              select g;
 
foreach (var empl in results)
{
    Console.WriteLine(empl.person_id + ", " + empl.first_name +
        empl.mid_name + ", " + empl.last_name + ", " + empl.empl_id);
}

Open in new window

0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 24818331
Hi IUAATech;

Are you still have issues with this?

Fernando
0
 

Author Comment

by:IUAATech
ID: 24853128
Thanks.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 24853171
Not a problem, glad to help.  ;=)
0

Featured Post

How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question