インデックス内に存在する行を検索しようとしていますが、インデックスに一致する行があっても結果がnullのままになります。私のクエリのロジックに何か問題はありますか?ここでインデックスの値がすべて存在する必要があるMySQLクエリの行を検索
は私のテストクエリです:
SELECT *
FROM `producthashtags_index`
WHERE `the_product_id` =54433
結果::
id producthashtag_id the_product_id
25433 6 54433
25434 41 54433
25435 42 54433
次に、あなたがあなたがthe_product_id
54433は、クエリを使用してインデックステーブルproducthashtags_index
内に存在する見ることができます。ここ
SELECT `the_products` . *
FROM `the_products`
INNER JOIN `producttypes_index` ON `producttypes_index`.`the_product_id` = `the_products`.`id`
AND `producttypes_index`.`type_id` = '1'
INNER JOIN `producthashtags_index` ON `producthashtags_index`.`the_product_id` = `the_products`.`id`
WHERE
`producthashtags_index`.`producthashtag_id`
IN ('41')
AND
`producthashtags_index`.`producthashtag_id`
IN ('42')
AND
`producthashtags_index`.`producthashtag_id`
IN ('6')
ORDER BY updated_at DESC
それはまた、インデックステーブル内に存在することがわかりますproducttypes_index
クエリを歌う:
SELECT *
FROM `producttypes_index`
WHERE `the_product_id` =54433
結果:
type_id the_product_id
1 54433
なぜあなたは3つの 'AND IN(...)'を持っていますか、 'IN( '42'、 '41'、 '6') 'を1つのステートメントで使用しますか?また、これを再作成できるようにスキーマを提供できますか? –
インデックスのすべての行が存在するように '42' AND '41' AND '6' '42' OR '41' OR '6'が必要です。 –
解決策が参照された重複した質問よりも複雑であるため、なぜ質問が重複とマークされたのか分かりません。 –