Select Random records then sort them.
Posted on 2007-04-02
I want to pull the first 10 random record, but then I want them in order by customer name.
The following query pulls the random 10 records, but I can't get them in order without messing up the random selection.
SELECT tblProducts.ProductID, tblProducts.Description, tblProducts.CustomerSKU,
tblProducts.QtyPerUnit, tblProducts.Units, tblCustomers.Name,
INNER JOIN tblInventory ON tblInventory.ProductID = tblProducts.ProductID
INNER JOIN tblCustomers ON tblCustomers.CustomerID = tblProducts.CustomerID
WHERE tblInventory.QtyOnHand > 0
AND tblCustomers.liveCustomer = 1
AND (tblInventory.AuditDate >= '04/02/2006' OR tblInventory.AuditDate IS NULL)
ORDER BY RAND() LIMIT 10