最好在语言代码中判断,再运行不同的SQL语句select p.id from products p,pd.description from products_description pd on(p.id=pd.id) where pd.language_id in (1,8) and p.id=125;

解决方案 »

  1.   

    铃铛 的SQL语句有问题吧?
    select .... from (
    select *,(select count(*) from products_description where language_id=8) as ss, from products_description .....
    )
    where language_id in (iif(ss=0,1,8)) 
      

  2.   

    select id, description from(
    select p.id, pd.description, 1 rank from products p inner join products_description pd
    on(p.id=pd.id) where pd.language_id =8 and p.id=125 
    union 
    select p.id, pd.description, 2 rank from products p inner join products_description pd
    on(p.id=pd.id) where pd.language_id =1 and p.id=125 ) tmp order by rank limit 1;
      

  3.   

    多谢楼上各位的指教,但实际代码比较复杂,if改动起来还是比较大, union的话不知道该怎么下手,烦请帮我分析一下,多谢。SELECT p.product_id,pd.description, (SELECT AVG(rating) AS total FROM ihu_review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating FROM ihu_product p LEFT JOIN ihu_product_description pd ON (p.product_id = pd.product_id) LEFT JOIN ihu_product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN ihu_product_to_category p2c ON (p.product_id = p2c.product_id) WHERE pd.language_id=8 AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '0' AND p2c.category_id = '78' GROUP BY p.product_id ORDER BY pd.language_id desc,p.sort_order ASC, LCASE(pd.name) ASC LIMIT 0,36
      

  4.   

    没办法,要么用语言代码实现
    要么修改SQL语句