You can do this using Custom actions. In actions.py file create an action like this:
from rasa_sdk import Action
def run(self, dispatcher, tracker, domain):
q = "SELECT <reponse> FROM <table> where <user_question> LIKE <user asked question> "
result = db.query(q)
Note: You need to install rasa_sdk using this command pip install rasa-sdk
and then use the custom action name action_response in your stories and don’t forget to add this custom action in your domain file.
To use custom actions you will need to run action server and you can run this by rasa run actions command and follow these docs for more details