使用外键不仅仅用于约束

时间:2019-01-04 15:00:42

标签: mysql foreign-keys

我想创建一个动态查询,该查询将基于外键知道我要连接的表。有没有办法利用外键呢?我想创建一个可以查找外键指向的位置的语句,并使用该语句选择正确的值。可能会像这样工作:

"SELECT t.*, f.Name FROM $table t INNER JOIN {foreign table(will change based on the table selected and the foreign key it has)} f WHERE t.key = '$key'";

0 个答案:

没有答案