Professional Web Applications Themes

Help writing a query - MySQL

Hi, I would be greatful if someone could help me in writing a query. I have a table as follows: NAME AGE Bob 44 Mary 59 James 32 I was wondering if I could select the row that had the nearest age to the one i specify. For example I could specify an age of 43. In this case the top row (Bob's info) would be returned as his age was the nearest to the age of 43 in the query. Thanks...

  1. #1

    Default Help writing a query

    Hi, I would be greatful if someone could help me in writing a query.

    I have a table as follows:

    NAME AGE
    Bob 44
    Mary 59
    James 32

    I was wondering if I could select the row that had the nearest age to
    the one i specify.

    For example I could specify an age of 43. In this case the top row
    (Bob's info) would be returned as his age was the nearest to the age of
    43 in the query.

    Thanks

    alexp Guest

  2. #2

    Default Help writing a query

    Hi, I would be greatful if someone could help me in writing a query.

    I have a table as follows:

    NAME AGE
    Bob 44
    Mary 59
    James 32

    I was wondering if I could select the row that had the nearest age to
    the one i specify.

    For example I could specify an age of 43. In this case the top row
    (Bob's info) would be returned as his age was the nearest to the age of
    43 in the query.

    Thanks

    alexp Guest

  3. #3

    Default Help writing a query

    Hi, I would be greatful if someone could help me in writing a query.

    I have a table as follows:

    NAME AGE
    Bob 44
    Mary 59
    James 32

    I was wondering if I could select the row that had the nearest age to
    the one i specify.

    For example I could specify an age of 43. In this case the top row
    (Bob's info) would be returned as his age was the nearest to the age of
    43 in the query.

    Thanks

    alexp Guest

  4. #4

    Default Re: Help writing a query

    In article <googlegroups.com>,
    alexp says... 

    SELECT `NAME`,`AGE`
    FROM `table`
    WHERE `AGE` = (
    SELECT MIN(ABS(`age`-43))
    FROM `table`
    );
    --
    PleegWat
    Remove caps to reply
    PleegWat Guest

Similar Threads

  1. mySQL query writing problem
    By JackM in forum MySQL
    Replies: 2
    Last Post: July 16th, 02:18 AM
  2. Writing Query for data range does not output
    By TonySDev in forum Coldfusion Database Access
    Replies: 2
    Last Post: January 13th, 02:27 PM
  3. I Need help writing a query
    By charlese in forum Coldfusion Database Access
    Replies: 1
    Last Post: March 17th, 03:22 PM
  4. Writing SQL query without subselect
    By Steven Stern in forum PHP Development
    Replies: 15
    Last Post: October 15th, 08:27 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