#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 1999
    Posts
    13
    Rep Power
    0
    I am trying to write a SQL(mySQL) query that would allow me to:

    Select any 2 records with the minimum numeric value in a certain field (let's say minimum age). Also, if for example, 10 is the minimum age and there is only one record in the table with that age, that record should be selected along with the record where the age is higher (say 11).

    Thanks in advance
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    couldn't you do something like this:

    select age from table order by age asc

    which will get all of the ages, and sort them in accending order. then you can just get the first two rows.

    you could possibly put a LIMIT on there to only retrieve two rows, but i've never used limits before...

    ---John Holmes...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    32
    Rep Power
    15
    select * from table order by age limit 0,2

Similar Threads

  1. Replies: 3
    Last Post: December 27th, 2003, 03:33 AM
  2. selecting duplicate records
    By crackerweb in forum Visual Basic Programming
    Replies: 3
    Last Post: November 12th, 2003, 12:10 PM
  3. selecting only records from specific month (ASP & MSSQL)
    By spackbace in forum ASP Programming
    Replies: 2
    Last Post: September 11th, 2003, 05:28 PM
  4. Selecting records based on a particular DAY..
    By ChrisIDS in forum MySQL Help
    Replies: 1
    Last Post: August 21st, 2003, 08:13 AM
  5. Selecting unmatched records?
    By SilkySmooth in forum MySQL Help
    Replies: 5
    Last Post: October 18th, 2001, 11:49 AM

IMN logo majestic logo threadwatch logo seochat tools logo