In addition to the instruction
\numberwithin{equation}{subsection}
you need the instructions
\makeatletter
\@addtoreset{equation}{section}
\makeatother
The first instruction, \numberwithin{equation}{subsection}
, resets the equation counter only when a \subsection
instruction is encountered. If you have a \section
instruction but no \subsection
instruction, the counter named equation
is not reset unless you provide an additional instruction, such as \@addtoreset{equation}{section}
.

Do note that if you do want to number the equations by subsection, it's probably not a good idea to feature equations between a \section
directive and that section's first \subsection
instruction: at that stage, the subsection
counter is still 0
(having been reset to 0
by the \section
directive), leading the equation numbers to be formatted as "2.0.1" and quite likely making your readers wonder if the subsection numbered 2.0
has somehow vanished mysteriously.
\documentclass{article}
\usepackage{amsmath}
\numberwithin{equation}{subsection}
\makeatletter
\@addtoreset{equation}{section}
\makeatother
\begin{document}
\section{Section 1 Title}
\subsection{Subsection 1.1 Title}
\begin{equation} a = b \end{equation}
\begin{equation} a+2=b+2 \end{equation}
\section{Section 2 Title}
%%\subsection{Subsection 2.1 Title}
\begin{equation} r=y \end{equation}
\end{document}