• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Linked table trying to eliminate multiple records

I was looking at the following article, and it looks as if it would solve my problem easily:
http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/Q_22820521.html?sfQueryTermInfo=1+custom+get+on+onli+per+queri+record

My scenario would be I have a table called Main, and each employee has a different User_ID where I simply want to show one of each User_ID in a query called Employee_Form.  The biggest difference between their problem and mine is that I don't have a date range that I care about.  I simply want one record shown for each User_ID.  The code I've used is:

SELECT *
FROM Main AS s INNER JOIN [select Emp_ID from Main group by Emp_ID]. AS q
ON s.Emp_ID = q.Emp_ID;

Please forgive my ignorance on SQL, and if there is a better way, I'm open to suggestions, but the reason i'm going through this is because I had to link tables together and by doing so have multiple entries for the same information.  Any thoughts would be greatly appreciated.  Thanks.
0
lstraw
Asked:
lstraw
  • 2
  • 2
1 Solution
 
SQL_SERVER_DBACommented:
SELECT s.*
FROM Main AS s INNER JOIN [Main group] q ON s.Emp_ID = q.EMP_ID;
0
 
SQL_SERVER_DBACommented:
SELECT distinct s.Emp_ID
FROM Main AS s INNER JOIN [Main group] q ON s.Emp_ID = q.EMP_ID;
0
 
lstrawAuthor Commented:
SQL_SERVER_DBA:
Neither of those worked, but I'm not sure if I'm doing it correctly.  Were there any variables that should be changed in either of those solutions?
0
 
lstrawAuthor Commented:
I found the problem.  You put the group statement ([Main group]) into Main.  When I took out group, I got the following:

SELECT distinct s.Emp_ID
FROM Main AS s INNER JOIN [Main] q ON s.Emp_ID = q.EMP_ID;

Which allows me to then add fields from design view. Thanks for all of your help!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now