Ramreddy
Electrolysing an ionic compound in its solution is very much different to electrolysing it when it’s molten. This is because in a solution we have 4 ions, H+ and OH- from water and a positive and a negative ion from the compound. But only one type of ions gets discharged at each electrode.
For the positive ions, the one that gets discharged at the cathode is the least reactive one. This is because least reactive elements have more tendencies to be an atom.
So if the ion from the ionic compound is above hydrogen in the reactivity series (more reactive), H+ gets discharged at the anode And if the ion from the compound is below hydrogen in the reactivity series (less reactive), this ion gets discharged at the cathode.