# Two different tables with different labels being referenced by the same number [duplicate]

I have two different tables, with two different labels: \label{lab1} and \label{lab2}. The tables were generated in the tables generator site and I am using Overleaf. When I reference these two tables, \ref{lab1} and \ref{lab2}, the text exhibits the same number for both tables: Table x.y and Table x.y, instead of Table x.y and Table x.z.

Here are the codes:

\begin{table}[!ht]
\label{lab1}
\caption{Text1}
\resizebox{\textwidth}{!}{%
\begin{tabular}{ll}
\rowcolor[HTML]{EFEFEF}
\multicolumn{1}{c}{\cellcolor[HTML]{EFEFEF}\textbf{Title 1}} & \multicolumn{1}{c}{\cellcolor[HTML]{EFEFEF}\textbf{Title 2}}             \\ \hline
ACM Digital Library (5)           & Some Text1                                \\ \hline
IEEE Xplore Digital Library (6)   & Some Text2        \\ \hline
Scopus (61)                       & Some Text3 \\ \hline
Springer Link (40)                & Some Text4    \\ \hline
ScienceDirect (23)                & Some Text5                  \\ \hline
Google Scholar (703)              & Some Text6                              \\ \hline
\end{tabular}%
}
\end{table}

\begin{table}[!ht]
\label{lab2}
\caption{Text2}
\resizebox{\textwidth}{!}{%
\begin{tabular}{ll}
\rowcolor[HTML]{EFEFEF}
\multicolumn{1}{c}{\cellcolor[HTML]{EFEFEF}\textbf{Title1}} & \multicolumn{1}{c}{\cellcolor[HTML]{EFEFEF}\textbf{Title2}}                                                                                                         \\ \hline
Text1           & \begin{tabular}[c]{@{}l@{}}aaaaaaaa\end{tabular}                  \\ \hline
Text2           & \begin{tabular}[c]{@{}l@{}}bbbbbbbbb\end{tabular}                         \\ \hline
Text3           & ccccccccc                                                                                                              \\ \hline
Text4           & \begin{tabular}[c]{@{}l@{}}ddddddddd\end{tabular} \\ \hline
\end{tabular}%
}
\end{table}


The \label{...} needs to be given after \caption{...} in each table, so that the label can hitch on to the updated table number. So you'll need to swap around your \label and \caption in both tables.