dbTalk Databases Forums  

Help writing a query

comp.databases.mysql comp.databases.mysql


Discuss Help writing a query in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
alexp
 
Posts: n/a

Default Help writing a query - 09-25-2006 , 10:12 AM






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


Reply With Quote
  #2  
Old   
PleegWat
 
Posts: n/a

Default Re: Help writing a query - 09-25-2006 , 12:15 PM






In article <1159197155.186851.167430 (AT) b28g2000cwb (DOT) googlegroups.com>,
alexp says...
Quote:
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
SELECT `NAME`,`AGE`
FROM `table`
WHERE `AGE` = (
SELECT MIN(ABS(`age`-43))
FROM `table`
);
--
PleegWat
Remove caps to reply


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.