It is not true that if $\frac{d}{dx}f(x) = q(x)$ and $\frac{d}{dx} u(x) = q(x)$ then $f(x) = u(x)$.
For example, suppose $f(x) = x^2 + 3$, and $u(x) = x^2 - 7$. Then $f'(x) = u'(x) = 2x$, but $f(x)\neq u(x).\;$
What we can say is that if $f'(x) = u'(x),\,$ then $f(x)$ and $u(x)$ differ by at most a constant.
Note that if you find the indefinite integral of, say $2x$, you'll obtain a family of functions $$\int 2x \,dx = x^2 + \text{any constant}$$ which, again, differ by at most a constant of integration.
So to answer your updated (new) question: In your polynomial example, only if we know that the two functions have exactly the same constant term, then yes, of course, $$f'(x) = u'(x) = 5\;\;\implies f(x) = u(x)$$ In other words, in your example, we essentially already have that $f(x) = u(x) = 5x + c $, so clearly, we'd necessarily have that $f'(x) = u'(x) = 5$, and we'd necessarily have $f(x) = u(x)$ not because their derivatives are the same, but because we started with the exact same functions $f(x) = u(x)$.
With integration, you'd get neither (or both) $f(x)$ and $u(x)$: You'd integrate $\int 5\,dx$ to obtain $5x + \text{any constant}$, which is a specific form of a function to denote that the integral represents the family of all functions that differ only in their constant term, and so both $f(x)$ and $u(x)$ belong the the family of function given by $5x + \text{constant}$.
You might want to read/review what is highly relevant to your question:
The Fundamental Theorem of Calculus.