Skip to content
Advertisement

SQL MAX() function seems to truncate results

I have the following basic 3 Table Structure in mariadb/mysql.

This simple SELECT returns incomplete records. I reduced the output of all follwing examples to a single dataset to avoid unnecessary clutter.

The IP_LONG column is missing the follwing for example…

My guess is, it has something to do with the MAX() Function has troubles with mixed Content in the Value Column. When leaving out MAX() and GROUP BY the missing Values are shown but Output is kind of chaotic.

This Query gives the right Output, but i am unclear how to integrate that in the above, but this is a Topic for another question.

Advertisement

Answer

These are the 3 values you are getting a max() of

These are strings — max looks at a “alphabetical” max. Since the “9” is greater than the 8 and the 1 the first one 172.17.9.196/255.255.248.0/172.17.15.255/ is picked. These values are all different — which do you want and why? Do you want the longest one? The longest one would require different code.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement