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
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;