Professional Web Applications Themes

top 3 of every category, in one query, is it possible? how... - PHP Development

Hi guys, here is my situation. i have a table that has :column that has the category number, and an another column that has a ranking. now i want to make a query to display the top 3 ranking from every category, so is there a way i can do that in one query? if not, what is the best way of doing this ? especially to reduce server overhead, since the top 3 are is on the home page. I thought about also assigning the results to another table and then assign the the table results to an array. ...

  1. #1

    Default top 3 of every category, in one query, is it possible? how...

    Hi guys, here is my situation. i have a table that has :column that has the
    category number, and an another column that has a ranking.
    now i want to make a query to display the top 3 ranking from every category,
    so is there a way i can do that in one query?
    if not, what is the best way of doing this ? especially to reduce server
    overhead, since the top 3 are is on the home page.
    I thought about also assigning the results to another table and then assign
    the the table results to an array. it is all a theory for now, until u
    suuggest some help.
    thanks
    Jim


    Jim Guest

  2. #2

    Default Re: top 3 of every category, in one query, is it possible? how...

    Jim S. wrote: 

    Maybe by having 3 Views (1. view for the highest rankings for each category, 2. for the
    second highest ranking and the 3. view for the third)
    Then just do an UNION on all three views

    Regards
    Stefan
    Stefan Guest

  3. #3

    Default Re: top 3 of every category, in one query, is it possible? how...

    can u give me an example please?
    I do not fully understand what do u mean by "Views"

    thanks

    "Stefan Rybacki" <net> wrote in message
    news:net... [/ref]
    the [/ref]
    category, [/ref]
    assign 
    >
    > Maybe by having 3 Views (1. view for the highest rankings for each[/ref]
    category, 2. for the 


    Jim Guest

  4. #4

    Default Re: top 3 of every category, in one query, is it possible? how...

    Jim S. wrote: 

    Depends on the DBMS you're using. I guess its mySQL, so views are available since mySQL
    Server 5
    If you're version supports subqueries you could go that way.

    1. create a query that retrieves the best ranked categorie entries
    2. create a query that retrieves the second ranked categorie entries
    3. create a query that retrieves the third ranked categorie entries

    4. UNION the 3 queries

    Example for the 1. query

    SELECT * FROM table t WHERE ranking=(SELECT MAX(ranking) FROM table WHERE
    category_id=t.category_id)

    Regards
    Stefan
    Stefan Guest

Similar Threads

  1. Many-to-Many with Sub Category
    By DdoubleU in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 0
    Last Post: December 20th, 07:13 PM
  2. Verity and Category
    By Bru_ in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: July 29th, 04:24 PM
  3. [PHP] Category and sub-category logic
    By Chris W. Parker in forum PHP Development
    Replies: 6
    Last Post: August 17th, 05:44 PM
  4. Category and sub-category logic
    By Ryan A in forum PHP Development
    Replies: 1
    Last Post: August 14th, 11:57 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139