Nimatullah Razmjo Nimatullah Razmjo - 4 months ago 7
MySQL Question

get reference table by foreign key

I have two table

user
and
course
where
user_id
is in table of
course
as foreign key.

How can I get referenced table from foreign key in php laravel framework. I mean is it possible ?

Any solution or other guide will be appreciate it.

Thank you!

Answer

If I understand correctly, then you can query the information_schema for this information:

SELECT `REFERENCED_TABLE_NAME` FROM `INFORMATION_SCHEMA`.`KEY_COLUMN_USAGE` WHERE `REFERENCED_TABLE_SCHEMA` = 'your_database' AND `TABLE_NAME` = 'course';
Comments