Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Duplicate Values in String Array

Status
Not open for further replies.

andstyles

Programmer
Jan 25, 2005
3
GB
I have searched through all the various postings but haven't found what I'm looking for.

I am trying to remove duplicate values from a string or array. Thus, producing a new, clean string/array without any duplication.

Heres the tricky part :

I want to produce one list of EmployeeID's from two different tables. But no duplicating values.

To populate my array I am performing the query "Select Distinct EmployeeID From TableA". No problem here. I then populate a second array with Distinct CustomerID From Table B. Then joining the two arrays together into one string.

The problem is I still have duplicating ID's if the same ID exists in both tables.

I'm probably overlooking a really simple way of doing this, but any help will be great.

Thank you!
 
combine both of them...something like this..

Code:
Select Distinct EmployeeID From TableA
UNION ALL
Select Distinct EmployeeID From TableB WHERE EmployeeID NOT EXISTS (Select Distinct EmployeeID From TableA)

-DNG

 
THANKS! That was brilliant, exactly what I was looking for. I'm a UNION newbie.

I played around with it somemore and found that UNION selects distinct values anyway, so no need for "UNION ALL Select Distinct".
And because my column names were different I did a "Select X AS Z UNION Y AS Z". Which worked a treat.

Thanks again for the help,
andstyles
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top