Skip to content
Advertisement

MySQL Query Returns Different Results

I’m having a strange problem with the following query:

Sometimes I get zero, one, two or three results. I should always get three results. What could be causing this?

Advertisement

Answer

As pointed out by Solarflare, GROUP_CONCAT() could produce your team string in a random order, e.g. 'Van Williams & Derek Williams' or 'Derek Williams & Van Williams'.

To remedy this, you can use an explicit ORDER BY within the GROUP_CONCAT(), e.g.:

See documentation and this db<>fiddle for an example.

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