Hopefully very simple SQL question - I'm just b开发者_开发知识库lacking out :)
I have a table of vendors (id, name, description, url). It used to be the web service returned them all sorted by id. After a while, I was asked to return sorted by name. Now they want me to allow them to change the order manually - to showcase new vendors.Suppose I create another table, VendorOrder with (vendorid, placement), what can I put in the Order By section of the original query, to return the vendors sorted by placement?
As always, thanks in advance.
Guyselect
vendor.id,
vendor.name,
vendor.description,
vendor.url
from
vendors,
vendorOrder
where
vendors.id = vendorOrder.vendorId
order by
vendorOrder.placement;
Make sure that you find exactly one vendorId in vendorOrder
for each id
in vendor
, otherwise use a left join
between the tables.
精彩评论