How to add if statement in SQL ?
- by shin
I have a following MySQL with two parameters, $catname and $limit=1.
And it is working fine.
SELECT P.*, C.Name AS CatName
FROM omc_product AS P
LEFT JOIN omc_category AS C
ON C.id = P.category_id
WHERE C.Name = '$catname'
AND p.status = 'active'
ORDER BY RAND()
LIMIT 0, $limit
Now I want to add another parameter $order.
$order can be either
ODER BY RAND()
or
ORDER BY product_order
in the table omc_product.
Could anyone tell me how to write this query please?
Thanks in advance.