A: How long have you been working in your present company?
B: I have working for last 5 years. (Or A could just say "5 years")
But this is conversational. We need to write a declarative sentence out of this. So we come up with the following sentence -
A asked B how long B had been working for his/her present company.
The verb of the subordinate clause have to be in the past tense - had - to agree with the verb of the superordinate clause - asked.
There is another logic for accepting had and rejecting have there. The process of asking is over, it's in the past. So in the past conversation A used have, but now when we are talking about the past event we need to use the past tense - had.
In the following sentence -
A asked B how long B had been working for his/her present company.
The part - how long B had been working for his/her present company - is a subordinate clause. It's called Embedded Interrogative clause.
You asked if the following sentence is correct -
I want to know did he really say that. [INCORRECT]
It's not correct sentence. We need a subordinator to introduce a subordinating clause. This subordinating clause is not like the one we discussed earlier. The earlier one was Embedded Interrogative clause, but this one is not like that. It's true that it's also an interrogative clause. But here in this case we must use a subordinator to introduce this clause.
I want to know if/whether he said that.