Solved

join on multiple tables

Posted on 2009-07-06
4
662 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 500 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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 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