6 messages in com.mysql.lists.mysqlRe: HAVING vs. WHERE| From | Sent On | Attachments |
|---|---|---|
| Jonathan Arnold | 05 Mar 2003 08:17 | |
| Stanimir Dzharkalov | 05 Mar 2003 08:39 | |
| Paul DuBois | 05 Mar 2003 08:46 | |
| Benjamin Pflugmann | 05 Mar 2003 09:01 | |
| Tore Bostrup | 05 Mar 2003 09:04 | |
| Dan Nelson | 05 Mar 2003 09:11 |
| Subject: | Re: HAVING vs. WHERE![]() |
|---|---|
| From: | Stanimir Dzharkalov (dun...@mtel.net) |
| Date: | 03/05/2003 08:39:03 AM |
| List: | com.mysql.lists.mysql |
go to http://www.mysql.com/doc/en/Miscellaneous_functions.html
and take a look at inet_ntoa and inet_aton
you may store IP addresses as integers and the query will be
SELECT inet_aton(inetAdr), * FROM Client WHERE inetAdr < inet_aton('240.0.0.0') OR inetAdr>inet_aton('239.255.255.255')
the inet_aton will return the IP dotted.
As well, you do not need to use HAVING here.
Hope this helps.
================== Stanimir Dzharkalov Developer Internet Division MobilTel EAD email: dun...@mtel.net ==================
----- Original Message ----- From: "Jonathan Arnold" <jdar...@buddydog.org> To: <mys...@lists.mysql.com> Sent: Wednesday, March 05, 2003 6:17 PM Subject: HAVING vs. WHERE
In the MySQL reference, it warns against using HAVING for items that "should" be in a WHERE clause. I'm not sure what items "should" be in a WHERE clause.
My exact problem is I want to select some records that have a dotted IP address as one of the fields. And I want to filter out the multicast addresses, which are the addresses that begin with the numbers in the range of 224. thru 239. This does it:
SELECT * FROM Client WHERE left(inetAdr,instr(inetAdr,"."))< 224 OR left(inetAdr,instr(inetAdr,".")) > 239
and this works as well:
SELECT *,left(inetAdr,instr(inetAdr,".")) as ia FROM Client HAVING ia < 224 OR ia > 239
and it is a little cleaner, although as I'm going to be doing this in a PHP script, cleanliness isn't all that important.
So I guess I have 2 questions:
1] Which should I use? 2] Is this the easiest way to check for the multicast address?
-- Jonathan Arnold (mailto:jdar...@buddydog.org) Amazing Developments http://www.buddydog.org
It ain't what you don't know that gets you into trouble. It's what you know for sure that just ain't so. Mark Twain
--------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <mysq...@lists.mysql.com> To unsubscribe, e-mail <mysql-unsubscribe-dune2=mtel...@lists.mysql.com> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




