Friday, July 06, 2012

mysql: query having condition

do you know that you can query with a condition that subjects a result in your selection?

ex. i want to know the character length of a field, so i do a...

mysql> select length(myfield) from mytable;

now if i want to get only those with length exceeding 160 characters, i do a...

mysql> select length(myfield) from mytable where length(myfield) > 160;

right. but have you tried 'having' command? apparently, you can also do a...

mysql> select length(myfield) as fieldlength from mytable having fieldlength > 160;

if you have a very complicated select formula, i'm sure you'll greatly appreciate not having to rewrite it accurately in the where portion of your query

yun lang ;)

No comments:

Post a Comment

SSH : No matching host key type found. Their offer: ssh-rsa,ssh-dss

Got this while connecting to my mikrotik router via ssh   Unable to negotiate with <ip address> port <ssh port>: no matching hos...