dtp87205 2013-03-29 11:58
浏览 6
已采纳

我想从table1随机获得产品,但我也想检查该产品的帐户公司是否已激活[关闭]

I have two tables products and company

I want to select 6 different products randomly from 'Products table' but I also want to check weather company of this product is activated or not. if its not activated my command must select some other product.

database Sql Language: Php

thanks for help

  • 写回答

1条回答 默认 最新

  • dongyou7292 2013-03-29 12:06
    关注

    Try this :

    SELECT products.* FROM products p
    INNER JOIN companies c 
    ON p.company_id = c.id AND c.active = 1
    ORDER BY RAND() LIMIT 6;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?