It goes to the person with the high card in the hand (or, better put, the person with the highest five card total)...example:

I hold:

you hold:


the board is:

My flush wins cuz I have the AKQJ7 club flush
your flush loses cuz you have AKT97, so your flush is lower than mine.