2013-12-10 188 views
-1

嗨任何人都可以帮助我的情况下,优化这个查询 鉴于类别表含1万分人次的纪录优化MySQL查询

SELECT a.title, a.item_id, b.image_path 
FROM category c INNER JOIN items a USING(item_id) 
INNER JOIN images b USING(item_id) 
where cat_id=(select cat_id from category where item_id=1) 
GROUP BY item_id 
ORDER BY item_id DESC 
limit 10; 
+1

为什么你使用'SELECT'在'WHERE'?无论如何,你都是'SELECT ... FROM category c'。所以我认为你可以使用'WHERE item_id = 1'而不是'where cat_id =(从类别where item_id = 1中选择cat_id)''。除此之外,如果不知道自己想要实现什么,需要优化什么以及如何优化数据库模式以及数据库模式如何...... – luckylwk

回答

0

CAT_ID在where子句是什么表?

猜你可以使用一些像:

SELECT 
    a.title, 
    a.item_id, 
    b.image_path 
FROM 
    items a, 
    images b, 
    category c 
WHERE 
    a.item_id=b.item_id 
AND 
    c.item_id = 1 
ORDER BY 
    a.item_id DESC 
+0

仍然缺少表c和a之间的连接,则难以“优化”某些内容。 – Dwza