这是我的查询
SELECT * FROM (
SELECT simple_sku, picture_url, product_name, discounted_price, tracking_link, 'Lazada.co.id' AS table_identity
FROM `list_lazada`
UNION
SELECT id_product, picture_url, product_name, sale_price, tracking_link, 'Simulation.com' AS table_identity
FROM `list_simulation`
) AS big_table
WHERE product_name LIKE '%$search%' ORDER BY big_table.discounted_price ASC
LIMIT 12 ";
现在使用phpmyadmin开发PHP。
每个表只有4列
如何使它更快?
您不需要外部子查询:
SELECT simple_sku, picture_url, product_name, discounted_price, tracking_link,
'Lazada.co.id' AS table_identity
FROM `list_lazada`
UNION
SELECT id_product, picture_url, product_name, sale_price, tracking_link,
'Simulation.com' AS table_identity
FROM `list_simulation`
WHERE product_name LIKE '%$search%'
ORDER BY discounted_price ASC
LIMIT 12
我认为你的LIKE
条件将使product_name
列上的索引不可用,导致全表扫描。但是也许你可以改进你的搜索方法来利用索引。