Hello!
I am trying to find common elements between 24 tables in access using VB 6.0. Currently I have developed the code for finding common elements between two columns in two tables only, you can see my pasted code.
The elements in the column "CustomerNo" have integer values, and the sql string returns the common elements found from the CustomerNo columns of two tables. This is the code:
Currently I am using this string, to find common elements amongst two table columns "CustomerNo", and the result from this is used with the third table column and so on for all 24 columns (uses a looping mechanism) to find the common values in all 24 table columns. The code is tidious and very slow indeed and not very effective.Code:Dim sql(0 To 11) As String Dim month(0 To 11) As String Dim lngPosition As Long Dim mtype As Variant mtype = Array("Month1", "Month2", "Month3", "Month4", "Month5", "Month6", "Month7", "Month8", "Month9", "Month10", "Month11", "Month12", "Month13", "Month14", "Month15", "Month16", "Month17", "Month18", "Month19", "Month20", "Month21", "Month22", "Month23", "Month24") Dim mno As Variant mno = Array("Month_1_and_2", "Month_3_and_4", "Month_5_and_6", "Month_7_and_8", "Month_9_and_10", "Month_11_and_12", "Month_13_and_14", "Month_15_and_16", "Month_17_and_18", "Month_19_and_20", "Month_21_and_22", "Month_23_and_24") 'INNER JOIN 24 records to obtain 12 records For lngPosition = LBound(month) To UBound(month) sql(lngPosition) = "SELECT DISTINCT " & mtype(lngPosition) & ".CustomerNo " _ & "FROM " & mtype(lngPosition) & " INNER JOIN " & mtype(lngPosition + 1) & "" _ & " ON " & mtype(lngPosition) & ".CustomerNo = " & mtype(lngPosition + 1) & ".CustomerNo" Set rs = cn.Execute(sql(lngPosition)) ......................... ..................... .................
If I want to find the common for the CustomerNo in between 24 tables? Is it possible to use this sql string or looping in my case is better? The 24 tables have the CustomerNo column, however the number of rows are different in each table. My only concern is using 24 Tables with INNER JOIN separately, would be very complex.. Any ideas on how to solve this?
regards,
JD


Reply With Quote
Assumingly, I don't have a very high end PC currently for simulation, my pc hangs up for the 24 loop..
since my data has 50,000+ customers on a monthly basis for two years..
hence I have divided it into three loops. The logic would be the same assumingly and give the same result in my opinion.
