hello - I'm hoping there is a good solution to a problem I'm having. I can probably figure out the details if someone can point me in the right direction.
Consider two tables.
In tblA, A1 >= A2 >= A3 >= A4.
In tblB, B1 >= B2 >= B3 >= B4 >= B5 >= B6 >= B7 >= B8 >= B9 >= B10
Here's my question. I need to DELETE all records in tblB that contain the values (A1, A2, A3, A4) as a subset.
In the example shown, record 101 gets deleted because it contains the from record 1:
Similarly, 104 gets deleted because it contains the values in record 3:
Note - record 100 DOES NOT get deleted. It has all the values in row 1, but it only has one 42.
tblA has 4 columns of data. If tblB also had the same number of columns, then I can just use a Left Join ON (A1 = B1) AND (A2 = B2) AND... ..WHERE tblB.B_ID IS NULL.
When tblB has 5 data columns, I can do something similar, but the 'ON' is more complicated...
My real problem is that tblB has so many data columns that the SQL has become completely lenghty and awkward. I'm hoping there is a better way.
Many thanks, Vicky
Consider two tables.
Code:
tblA tblB
A_ID A1 A2 A3 A4 B_ID B1 B2 B3 B4 B5 B6 B7 B8 B9 B10
1 45 42 42 36 100 75 45 45 43 42 41 36 23 11 9
2 54 29 21 8 101 65 50 45 44 44 42 42 39 36 33
3 35 35 13 10 102 56 52 50 51 37 33 29 10 7 3
4 etc... 104 45 42 39 35 35 35 35 30 13 10
105 etc...
In tblA, A1 >= A2 >= A3 >= A4.
In tblB, B1 >= B2 >= B3 >= B4 >= B5 >= B6 >= B7 >= B8 >= B9 >= B10
Here's my question. I need to DELETE all records in tblB that contain the values (A1, A2, A3, A4) as a subset.
In the example shown, record 101 gets deleted because it contains the from record 1:
Code:
1 [b]45 42 42 36[/b] 101 65 50 [b]45[/b] 44 44 [b]42 42[/b] 39 [b]36[/b] 33
Similarly, 104 gets deleted because it contains the values in record 3:
Code:
3 [b]35 35 13 10[/b] 104 45 42 39 [b]35 35[/b] 35 35 30 [b]13 10[/b]
Note - record 100 DOES NOT get deleted. It has all the values in row 1, but it only has one 42.
tblA has 4 columns of data. If tblB also had the same number of columns, then I can just use a Left Join ON (A1 = B1) AND (A2 = B2) AND... ..WHERE tblB.B_ID IS NULL.
When tblB has 5 data columns, I can do something similar, but the 'ON' is more complicated...
Code:
ON (((A1=B1) AND A2=B2) AND A3=B3) AND A4=B4)) OR ((A1=B1) AND A2=B2) AND A3=B3) AND A4=[b]B5[/b])) OR ... etc.
My real problem is that tblB has so many data columns that the SQL has become completely lenghty and awkward. I'm hoping there is a better way.
Many thanks, Vicky