mySQL 从不同表中选择列
1000 抱歉,如果我重复了一个问题,但在此处找不到我的问题的答案。
我尝试从同一查询中的 2 个不相关表的 2 个独立列中检索数据。
我尝试过使用 UNION 语句,但问题是我需要能够将结果分为“场地”和“节目” - 这就是我所做的:
SELECT venue_name
FROM my_venues
UNION
SELECT programme_title
FROM my_programmes;
也许没有必要合并查询,我可以只做 2 个单独的查询吗?数据库不会特别大,但似乎没有必要......
帮助和感谢!
1000 Apologies if I've repeated a question, couldn't find an answer here to my question.
I'm try to retrieve the data from 2 separate columns from 2 unrelated tables in the same query.
I've tried using a UNION
statement, but the problem is that I need to be able to separate the results into 'venues' and 'programmes' - here was what I did:
SELECT venue_name
FROM my_venues
UNION
SELECT programme_title
FROM my_programmes;
Maybe it's not necessary to combine the query and I can just do 2 separate queries? The database won't be especially large, but it seems unnecessary...
Help and thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在两个选择中添加一个具有相同名称但不同值的常量列:
现在:
source
将来自表格my_venues
,列
source
将来自表我的程序
。Just add a constant column in both selects, with the same name, but different values:
Now:
source
will come from the tablemy_venues
,column
source
will come from tablemy_programmes
.