I have the following tables(only listing the required attributes)
- medicine (id, name),
- generic (id, name),
- med_gen (med_id references medicine(id),gen_id references generic(id), potency)
Sample Data
medicine
- (1, 'Crocin')
- (2, 'Stamlo')
- (3, 'NT Kuf')
generic
- (1, 'Hexachlorodine')
- (2, 'Methyl Benzoate')
med_gen
- (1, 1, '100mg')
- (1, 2, '50ml')
- (2, 1, '100mg')
- (2, 2, '60ml')
- (3, 1, '100mg')
- (3, 2, '50ml')
I want all the medicines which are equivalent to a given medicine. Those medicines are equivalent to each other that have same generic as well as same potency. In the above sample data, all the three have same generics, but only 1 and three also have same potency for the corresponding generics. So 1 and 3 are equivalent medicines.
I want to find out equivalent medicines given a medicine id.
NOTE : One medicine may have any number of generics. Medicine table has around 102000 records, generic table around 2200 and potency table around 200000 records. So performance is a key point.
NOTE 2 : The database used in MySQL.