Professional Web Applications Themes

top 3 query, how? - PHP Development

hi guys, I have a table that am calculating number of clicks in it, how can i make a query that will give me the top 3 (or what ever number, 4, or 5 ...) my brain at this moment 4:00 AM does not seem to want to help me out, so please help. thanks Jim if u feel like it, maybe u can help with the next question (am doing a different post for it too) i did this before, but i forgot what i used, anyhow, i have a field that maybe 255 characters, i want to display ...

  1. #1

    Default top 3 query, how?

    hi guys,
    I have a table that am calculating number of clicks in it, how can i make a
    query that will give me the top 3 (or what ever number, 4, or 5 ...) my
    brain at this moment 4:00 AM does not seem to want to help me out, so please
    help.
    thanks
    Jim

    if u feel like it, maybe u can help with the next question (am doing a
    different post for it too)
    i did this before, but i forgot what i used,
    anyhow, i have a field that maybe 255 characters, i want to display only
    100, how can i do that?
    thanks again
    Jim


    Jim Guest

  2. #2

    Default Re: top 3 query, how?

    Jim S. wrote: 

    Which RDBMS are you using?

    mySQL knows LIMIT

    SELECT clicks FROM clicktable ORDER BY clicks DESC LIMIT 1,3


    SQLServer for example has the TOP keyword

    SELECT TOP 3 clicks FROM clicktable ORDER BY clicks DESC

     

    Do you want a SQL solution or a PHP one?

    SQL: have a look at aggregat functions for Strings like SUBSTRING
    $text100=PHP substr($text,0,100);


    Regards
    Stefan 
    Stefan Guest

  3. #3

    Default Re: top 3 query, how?

    Stefan Rybacki said the following on 27/06/2005 10:56: 
    >
    >
    > Which RDBMS are you using?
    >
    > mySQL knows LIMIT
    >
    > SELECT clicks FROM clicktable ORDER BY clicks DESC LIMIT 1,3
    >[/ref]

    That should be:

    LIMIT 0, 3

    or:

    LIMIT 3

    Row-numbering starts from 0.


    --
    Oli
    Oli Guest

  4. #4

    Default Re: top 3 query, how?

    Oli Filth wrote: 
    >>
    >>
    >>
    >> Which RDBMS are you using?
    >>
    >> mySQL knows LIMIT
    >>
    >> SELECT clicks FROM clicktable ORDER BY clicks DESC LIMIT 1,3
    >>[/ref]
    >
    > That should be:
    >
    > LIMIT 0, 3
    >
    > or:
    >
    > LIMIT 3
    >
    > Row-numbering starts from 0.
    >[/ref]

    Yes of course, sorry.

    Stefan Guest

  5. #5

    Default Re: top 3 query, how?

    thank u very much guys, that was super.

    note: am using php and mysql


    "Jim S." <com> wrote in message
    news:QBOve.12809$news.atl.earthlink.net... 

    please 


    Jim Guest

Similar Threads

  1. Query of Queries on query New type query
    By david_h in forum Coldfusion Database Access
    Replies: 2
    Last Post: May 6th, 08:55 PM
  2. Replies: 2
    Last Post: August 6th, 07:08 PM
  3. Replies: 1
    Last Post: July 2nd, 09:09 AM

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