MySQL - 是否可以使用列作为表名?

发布于 2024-12-03 16:02:30 字数 262 浏览 7 评论 0原文

假设我们在 mysql 中有一个表“mytable”,

其中包含以下列:id、title、type

是否可以在同一查询中使用其列作为表名?

例如:

SELECT m.id, m.title FROM mytable m INNER JOIN m.type WHERE m.id=2

其中“type”将为我提供进行内部联接的表的名称。

Suppose that we have, in mysql, a table "mytable"

with the columns: id, title, type.

Is it possible to use its column as a table name in the same query?

For example:

SELECT m.id, m.title FROM mytable m INNER JOIN m.type WHERE m.id=2

Where "type" will give me the name of the table to do the inner join.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖心男生 2024-12-10 16:02:30

不,对不起 :(

你能得到的最接近的(据我所知)是光标浏览你的主表并为每行的连接编写动态 html。非常慢。

或者,找到一个新的设计模式 - 你是否有空间发布关于您想要实现什么目标以及人们如何实现这一目标的问题?

No, Sorry :(

The closest you can get (afaik) is to cursor through your main table and write dynamic html for the join for each row. VERY slow.

Or, find a new design pattern - Is there scope for you to post a question about what you are trying to achieve and how people may go about that?

み青杉依旧 2024-12-10 16:02:30

为什么不将所有类型数据放在一个表中?然后按类型对表进行分区。

Why not put all of your type data in a single table ? and then partition the table by type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文