CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2005
    Posts
    568

    Lightbulb query top10 value

    can i query the top 10 value in database using sql statement??
    i had a series of data... which i just want the top 10 largest value to be display...
    pls advice...

  2. #2
    Join Date
    Jul 2004
    Location
    Jakarta, Indonesia
    Posts
    596

    Re: query top10 value

    something like
    Code:
    SELECT TOP 10 field_name FROM table_name ORDER BY field_largest DESC
    plz give more detail like table name, table value if it's not working

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL

  3. #3
    Join Date
    Feb 2005
    Posts
    568

    Re: query top10 value

    Quote Originally Posted by erickwidya
    something like
    Code:
    SELECT TOP 10 field_name FROM table_name ORDER BY field_largest DESC
    plz give more detail like table name, table value if it's not working
    this will return the top 10 record not the value of a column...
    eg:
    counterA
    6
    11
    5
    3
    12
    7
    10
    2
    8
    9

    i want it return as
    counterA
    12
    11
    10
    9
    8
    7
    6
    5
    4
    3

    you get what i means?

  4. #4
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    Re: query top10 value

    I would query it like this :
    Code:
    SELECT field_name FROM tabl_name ORDER BY field_largest DESC LIMIT 10
    Thats how I do it, and it ususally works...
    Rate this post if you found it useful!
    10X, gilly914

  5. #5
    Join Date
    Feb 2005
    Posts
    568

    Re: query top10 value

    Quote Originally Posted by gilly914
    I would query it like this :
    Code:
    SELECT field_name FROM tabl_name ORDER BY field_largest DESC LIMIT 10
    Thats how I do it, and it ususally works...
    It does not work... i'm using MS Access to make this query... it does not recognise the LIMIT 10... pls advice...

  6. #6
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    2,147

    Re: query top10 value

    Quote Originally Posted by lsy
    this will return the top 10 record not the value of a column...
    eg:
    counterA
    6
    11
    5
    3
    12
    7
    10
    2
    8
    9

    i want it return as
    counterA
    12
    11
    10
    9
    8
    7
    6
    5
    4
    3

    you get what i means?
    I do not beleive this to be correct.

    The order by will be called before the top 10 is selected, which should give you what you desire. This will work in Access.

    So, as Erick suggested, I think this is what you need:
    Code:
    SELECT TOP 10 field_name FROM table_name ORDER BY field_largest DESC
    Hope this helps,

    - Nigel

  7. #7
    Join Date
    Jul 2004
    Location
    Jakarta, Indonesia
    Posts
    596

    Re: query top10 value

    try this one
    Code:
    SELECT TOP 10 CounterA from table_name ORDER BY CounterA DESC

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL

  8. #8
    Join Date
    Jul 2004
    Location
    Chennai, India
    Posts
    1,064

    Re: query top10 value

    >>SELECT field_name FROM tabl_name ORDER BY field_largest DESC LIMIT 10

    That is for MySQL

    >>this will return the top 10 record not the value of a column...

    Did you try the Query suggested by erickWidya
    Thats the answer
    It seems you didnt try that
    What do you mean by "this will return the top 10 record not the value of a column..."?
    Madhivanan

    Failing to plan is Planning to fail

  9. #9
    Join Date
    Feb 2005
    Posts
    568

    Re: query top10 value

    Thanks all.... i been success to query about... but right now i have some concern if i have a largest value data which have more than 10 times how can i control which only display 10 record??
    eg:
    counter a:
    12
    12
    12
    12
    12
    12
    12
    12
    12
    12
    12
    12
    12

  10. #10
    Join Date
    Jul 2004
    Location
    Chennai, India
    Posts
    1,064

    Re: query top10 value

    Select Distinct Top 10 CounterA from yourTable ORDER BY CounterA DESC
    Madhivanan

    Failing to plan is Planning to fail

  11. #11
    Join Date
    Feb 2005
    Posts
    568

    Re: query top10 value

    Thanksss all...

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured