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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get id's that appear in all x number of lists

Status
Not open for further replies.

kloner

Programmer
May 15, 2000
79
AU
hi all.

I'll try my best at explaining this problem. I have 5 seperate queries (which will not be merged for specific reasons). Each list returns a list of ID's (if any are available).

A min of 1 list and up to 5 lists can be returned.

list1 = "1,2,3,4,5,6,7,8,19"
list2 = "1,5,6,7,8,19"
list3 = "1,5,6,7,19"
list4 = "1,3,4,7,15,17,19"
list5 = "1,7,18,19"

What I need to do is somehow retrieve the id's that appear in all lists. For the example above I would require a new list with :

new_list = "1,7,19"

Note : The number of lists could actually be 1,2,3,4 or 5 of them.

Has anyone actually done anything like this before??

I have thought of an idea, maybe this :

1. Count all list with values in it (eg 5 times).
2. Make a big list of all id's from all lists
3. For each id in the smallest list (eg list5) check if that value exists in the new big list 5 times.
4. if it does append to a new unquie id list.
5. and so forth ....

Does anyone out there have an suggestions about this??

Any ideas would be much appreciated.

kloner
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top