SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    May 2006
    Posts
    457
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sql order by problem

    Hello all,

    I have the following table (+ example rows):
    Company(string), ProductID(int), Cost(decimal)
    Argos, 1, 1.00
    Tesco, 1, 1.00
    Tesco, 2, 1.00
    Argos, 2, 1.00
    Asda, 3, 1.00

    Im pulling the following results from the table:
    SELECT * FROM table WHERE Cost = 1.00

    Is there an way of me ordering the table by alternative CompanyIDs? I do not want all of 1 companies products to be displayed first. I would like alternative companies to be displayed

    e.g. In the above examples, I would like the following to be returned:
    Argos,
    Tesco,
    Asda,
    Argos,
    Tesco.

    Can this be done in the sql query?

  2. #2
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can order it by alternate criteria, but what is that critera? Is it productid? if so: ORDER BY ProductId, Company.

    Does that accomplish what you are after?

  3. #3
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    you could randomize the order, but there's no way to make sure two consecutive entries are not from the same company.


Bookmarks

Posting Permissions

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