parent items sub items sub attributes - candy - snickers ~12 size (t1): small - flavor (t2): classic ~13 size (t1): large - flavor (t2): classic ~18 size (t1): med - flavors (t2): with almonds ~55 size (t1): med - flavor (t2): classic - candy - m&m's ~16 size ((t1): small - flavor (t2): classic ~23 size (t1): large - flavor (t2): classic ~68 size (t1): med - flavors (t2): with almonds ~45 size (t1): med - flavor (t2): classic ~99 size (t1): med - flavor (t2): peanut - fruit - peaches ~100 size (t5): small - color/flavor (t3): white ~101 size (t5): med - color/flavor (t3): red ~102 size (t5): large - color/flavor (t3): yellow - fruit - apples ~110 size (t5): small - color/flavor (t3): green ~111 size (t5): med - color/flavor (t3): red ~112 size (t5): large - color/flavor (t3): yellow now lets search by: sub attribute size (t1 and a t5): flavor (t2): color/flavor (t3): scenario 1: search by size: med ~18, ~55, ~68, ~45, ~99, ~101, ~111 backend thinking... start with the name "size" find all sub attributes that match that sql = SELECT attribute_column, column_number, attribute_name, part_category_id, data_type_table FROM sub_inventory_attributes WHERE corp_id = 53 AND attribute_name = 'size' AND attribute_status = 1 ORDER BY part_category_id candy - t1 = size fruit - t5 = size t1 >> custom_text and column 1 t5 >> custom_text and column 5 sql = SELECT column_number, data_value, parent_id AS sub_reference_id FROM custom_text WHERE corp_id = 53 AND column_number IN (1,5) AND parent_table = 'time_sub_inventory_53' AND parent_column = 'sub_reference_id' AND data_value = 'med' ORDER BY sub_reference_id results = 18, 55, 68, 45, 99, 101, 111 pass the list into another query to get the real packages.