I
Ivor Somerset
Hi,
I've an Access DB table ("Groups") where data are as follow:
Id Group Rank Item
1 1 1 7364
2 1 2 283
3 1 3 34888
4 2 1 277
5 2 2 8233
(...)
Each record belongs to a group in which it has a rank.
I have an ASP script that writes new groups in the table, but before
writing anything, I'd need to check whether a similar group already
exists, and I think it can be done with a single sql statement. (NB:A
group is similar to another if it has the same Item value at the same Rank.)
The group I want to check is stored in a dictionary object (where the
key stands for the rank).
My basic idea is to iterate through the items to build an sql statement
with nested SELECTs:
sql = "Groups"
For Each a In Dict.Keys
sql = "SELECT * FROM (" & sql1 & ") WHERE Item=" & Dict.Item(a) & " AND
Rank=" & a
Next
sql1 = sql1 & ";"
RS1.Open sql1,Conn
But... of course it doesn't work because the first SELECT matches a
definite record from which the second iteration matches nothing. What I
should have is a set of all groups where the Item at Rank 1 is equal to
the given Item, and so on.
So I guess there should be some (self-)JOIN in the sql statement, but so
far all my attemps have failed.
Any idea? Thanks a lot in advance.
Ivor
I've an Access DB table ("Groups") where data are as follow:
Id Group Rank Item
1 1 1 7364
2 1 2 283
3 1 3 34888
4 2 1 277
5 2 2 8233
(...)
Each record belongs to a group in which it has a rank.
I have an ASP script that writes new groups in the table, but before
writing anything, I'd need to check whether a similar group already
exists, and I think it can be done with a single sql statement. (NB:A
group is similar to another if it has the same Item value at the same Rank.)
The group I want to check is stored in a dictionary object (where the
key stands for the rank).
My basic idea is to iterate through the items to build an sql statement
with nested SELECTs:
sql = "Groups"
For Each a In Dict.Keys
sql = "SELECT * FROM (" & sql1 & ") WHERE Item=" & Dict.Item(a) & " AND
Rank=" & a
Next
sql1 = sql1 & ";"
RS1.Open sql1,Conn
But... of course it doesn't work because the first SELECT matches a
definite record from which the second iteration matches nothing. What I
should have is a set of all groups where the Item at Rank 1 is equal to
the given Item, and so on.
So I guess there should be some (self-)JOIN in the sql statement, but so
far all my attemps have failed.
Any idea? Thanks a lot in advance.
Ivor