从 UNION 查询中识别源表 [英] Identifying source table from UNION query

查看:20
本文介绍了从 UNION 查询中识别源表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 PHP 构建一个 RSS 提要,它使用来自三个单独表的数据.这些表格都引用了站点不同区域内的页面.我遇到的问题是尝试在 XML 中创建链接字段.如果不知道每条记录来自哪个表,我就无法创建正确的链接.

I'm building an RSS feed in PHP which uses data from three separate tables. The tables all refer to pages within different areas of the site. The problem I have is trying to create the link fields within the XML. Without knowing which table each record has come from, I cannot create the correct link to it.

有没有办法解决这个问题?我尝试使用 mysql_fetch_field,但它返回表的空白值.

Is there a way to solve this problem? I tried using mysql_fetch_field, but it returned blank values for the tables.

SELECT Title FROM table1
UNION 
SELECT Title FROM table2
UNION 
SELECT Title FROM table3

还涉及其他字段,但这基本上是我使用的查询.

There are other fields involved, but this is basically the query I'm using.

推荐答案

应该很简单,做这样的事情:

Should be easy enough, just do something like this:

SELECT Title, 1 FROM table1
UNION ALL
SELECT Title, 2 FROM table2
UNION ALL
SELECT Title, 3 FROM table3

这篇关于从 UNION 查询中识别源表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆