SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Zend - Find number or the second largest number

    How can i find second largest number in case i dont find the number i've searched?
    for example
    i am searching 3000 and on my db the largest number i've got is 2900 how can i find the second largest?


    PHP Code:
            $query $select->from('numbers', array(
                
    'id'))
                ->
    where('number=?',$big_number); 

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty sure that this is what you're asking for.

    Code SQL:
    SELECT `number` FROM `table` WHERE `number` <= ? ORDER BY `number` DESC LIMIT 2;

    Failing that, you maybe after this.

    Code SQL:
    SELECT DISTINCT `number` FROM `table` WHERE `number` <= ? ORDER BY `number` DESC LIMIT 2;
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


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
  •