Certainly A51 comes out better on specifications and has faster processor. See comparison here https://www.gadgetsnow.com/compare-mobile-phones/Samsung-Galaxy-A30-vs-Samsung-Galaxy-A51
see information about 5G version here https://www.sammobile.com/samsung/galaxy-a51-5g
See prices on Samsung site here: https://www.samsung.com/uk/smartphones/galaxy-a-series/
If your preference is extra Camera features like slow mo, complete Pro Mode, super slow mo, night hyperlapse, super steady mode, 4k recording and better gaming(Not a gaming phone but its performs much better than Galaxy A31) and 3 years of software updates then you should definately go with Galaxy A51 but if you are power user and battery timing is most important to you then go with Galaxy A31.