lstraw
asked on
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:
https://www.experts-exchange.com/questions/22820521/Query-to-get-only-one-record-per-customer-based-on-ID.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.
https://www.experts-exchange.com/questions/22820521/Query-to-get-only-one-record-per-customer-based-on-ID.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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
ASKER
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!
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!
FROM Main AS s INNER JOIN [Main group] q ON s.Emp_ID = q.EMP_ID;