Order by count(brand), Y/N??

Results 1 to 2 of 2

Thread: Order by count(brand), Y/N??

  1. #1
    Join Date
    Dec 1969

    Default Order by count(brand), Y/N??

    Hi,<BR><BR>I want to be able to output data from my databse where a shop that carries the most brands is outputted first, second most next and so on.<BR><BR>My database is something like this <BR><BR>ShopID Brand <BR><BR>1 Sony<BR>1 Bose<BR>1 Yahmaha<BR>2 Sony<BR>2 Philips<BR>3 Sony<BR>3 Bose<BR>3 Yahmaha<BR>3 Sony<BR>3 Philips<BR><BR>Where a single instancec of Shop 3 is first, then shop 1, then shop 2<BR>Do I use count () or a subquery ??<BR><BR>Thanks

  2. #2
    Join Date
    Dec 1969

    Default Easy enough...

    SELECT Shopid, Count(Brand)<BR>FROM table<BR>GROUP BY Shopid<BR>ORDER BY Count(Brand) DESC<BR><BR>Then just ignore the count field when you display the results, if you don&#039;t care about it.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts