SELECT
    distinct_keywords.keyword_phrase,
    km.categoryAttributes
FROM (
    SELECT DISTINCT
        apk.product_id,
        ak.keyword_phrase,
        ak.id as keyword_id
    FROM
        `viko-lab.aquila.amz_product_keywords` apk
    JOIN
        `viko-lab.aquila.amz_keywords` ak ON apk.keyword_id = ak.id
    WHERE
        apk.product_id IN (
            314399, 314409, 314428, 314441, 314405, 314421, 314385, 314365, 314431, 314400,
            314384, 314364, 314433, 314425, 314412, 314391, 314366, 314367, 314435, 314380,
            314381, 314372, 314361, 314370, 314403, 314379, 314402, 314394, 314389, 314396,
            314392, 314438, 314360, 314382, 314422, 314418, 314373, 314383, 314443, 314424,
            314429, 314369, 314368, 314406, 314411, 314378, 314416, 314395, 314358, 314417,
            314430, 314388, 314393, 314371, 314397, 314442, 314439, 314427, 314376, 314410,
            314426, 314359, 314362, 314413, 314408, 314390, 314363, 314387, 314437, 314377,
            314386, 314407, 314420, 314401, 314440, 314436, 314375, 314423, 314398, 314414,
            314374, 314434, 314432, 314404, 314415, 314419, 314446, 314445, 314444, 314452,
            314449, 314447, 314451, 314453, 314450, 314448, 314517, 314534, 314454, 314455,
            314521, 314538, 314477, 314516, 314488, 314465, 314543, 314518, 314468, 314471,
            314504, 314480, 314549, 314476, 314467, 314463, 314462, 314500, 314483, 314528,
            314495, 314475, 314539, 314472, 314470, 314514, 314519, 314507, 314547, 314501,
            314536, 314548, 314532, 314520, 314460, 314523, 314486, 314541, 314490, 314457,
            314544, 314497, 314458, 314529, 314485, 314550, 314459, 314487, 314505, 314552,
            314533, 314551, 314537, 314522, 314546, 314499, 314496, 314524, 314479, 314513,
            314531, 314535, 314506, 314461, 314456, 314473, 314509, 314474, 314464, 314515,
            314494, 314482, 314525, 314466, 314530, 314540, 314545, 314484, 314491, 314510,
            314502, 314512, 314489, 314527, 314526, 314542, 314511, 314469, 314508, 314503,
            314492, 314493, 314481, 314478, 314498, 314591, 314601, 314625, 314622, 314624,
            314609, 314589, 314577, 314602, 314618, 314627, 314569, 314608, 314603, 314600,
            314599, 314554, 314573, 314578, 314610, 314555, 314611, 314616, 314629, 314590,
            314630, 314558, 314584, 314585, 314587, 314594, 314561, 314604, 314581, 314566,
            314615, 314580, 314607, 314562, 314557, 314556, 314617, 314572, 314632, 314565,
            314636, 314593, 314626, 314631, 314595, 314588, 314620, 314597, 314575, 314598,
            314553, 314621, 314571, 314586, 314564, 314628, 314560, 314619, 314563, 314570,
            314633, 314576, 314605, 314559, 314567, 314635, 314623, 314574, 314613, 314579,
            314606, 314614, 314583, 314612, 314568, 314582, 314637, 314592, 314634, 314596,
            314706, 314698, 314692, 314679, 314697, 314675, 314703, 314680, 314646, 314678,
            314643, 314683, 314644, 314707, 314693, 314690, 314687, 314660, 314641, 314666,
            314652, 314654, 314670, 314669, 314682, 314663, 314647, 314709, 314684, 314649,
            314681, 314656, 314671, 314658, 314662, 314645, 314677, 314659, 314695, 314642,
            314704, 314691, 314702, 314696, 314655, 314674, 314700, 314665, 314664, 314650,
            314639, 314688, 314667, 314708, 314651, 314657, 314640, 314699, 314653, 314689,
            314668, 314648, 314694, 314673, 314701, 314638, 314686, 314661, 314685, 314676,
            314705, 314672, 314711, 314710, 314755, 314750, 314754, 314787, 314789, 314771,
            314729, 314726, 314728, 314745, 314758, 314724, 314796, 314757, 314761, 314744,
            314792, 314715, 314733, 314768, 314723, 314781, 314759, 314722, 314756, 314719,
            314784, 314753, 314799, 314720, 314751, 314736, 314741, 314714, 314717, 314788,
            314798, 314797, 314775, 314739, 314790, 314743, 314738, 314794, 314782, 314721,
            314712, 314713, 314734, 314786, 314793, 314727, 314742, 314716, 314785, 314777,
            314773, 314772, 314795, 314735, 314760, 314752, 314740, 314769, 314776, 314791,
            314748, 314783, 314778, 314800, 314737, 314762, 314779, 314732, 314780, 314765,
            314770, 314718, 314767, 314749, 314730, 314747, 314774, 314763, 314764, 314766,
            314725, 314746, 314731, 314801, 314802, 314803, 314836, 314848, 314872, 314878,
            314869, 314813, 314826, 314887, 314851, 314858, 314829, 314827, 314860, 314853,
            314882, 314816, 314837, 314814, 314850, 314815, 314868, 314841, 314865, 314845,
            314828, 314876, 314805, 314875, 314871, 314808, 314830, 314811, 314823, 314822,
            314886, 314843, 314818, 314810, 314804, 314857, 314833, 314873, 314863, 314835,
            314831, 314880, 314866, 314844, 314883, 314885, 314807, 314861, 314856, 314849,
            314867, 314854, 314847, 314842, 314821, 314840, 314809, 314817, 314864, 314824,
            314838, 314812, 314855, 314859, 314806, 314832, 314846, 314834, 314879, 314820,
            314884, 314870, 314862, 314881, 314852, 314839, 314874, 314877, 314825, 314819,
            314954, 314903, 314957, 314895, 314959, 314948, 314947, 314896, 314923, 314953,
            314939, 314929, 314960, 314940, 314962, 314890, 314906, 314944, 314919, 314888,
            314951, 314952, 314917, 314956, 314938, 314902, 314911, 314949, 314932, 314892,
            314958, 314943, 314933, 314945, 314941, 314927, 314913, 314920, 314926, 314899,
            314916, 314946, 314901, 314905, 314909, 314931, 314950, 314934, 314942, 314889,
            314893, 314904, 314936, 314955, 314961, 314907, 314915, 314935, 314922, 314891,
            314908, 314937, 314900, 314928, 314921, 314898, 314918, 314914, 314912, 314910,
            314897, 314925, 314930, 314894, 314924, 314966, 314963, 314964, 314965
        )
) AS distinct_keywords
LEFT JOIN
    `viko-lab.aquila.keyword_metadata` km ON distinct_keywords.keyword_phrase = km.keyword_phrase
ORDER BY
    distinct_keywords.keyword_phrase;