I was trying to show that if $G$ has order $p^3$ and is not abelian, then $Z(G)$ is the commutator subgroup.
Working out one of the cases, we get that if
$$|Z(G)|=p^2 \implies |G/Z(G)|=p \implies G/Z(G) \text{ is abelian}$$
I am trying to prove that $G$ is abelian and get to a contradiction. I know the groups $G/Z(G)$ and $Z(G)$ are of a completely different nature but if it was possible to bring $G/Z(G)$ to a subgroup $K$ of $G$ that is isomorphic to $G/Z(G)$ by $\varphi: G/Z(G) \to K$ then we could write $G=\varphi(G/Z(G))\times Z(G)$ and since both factors are abelian, $G$ would be abelian.
I wonder if it makes any sense in this example but also in a more general scenario.