我有 2 个表。表 1 有字段 A、B、C、D,表 2 有字段 A、B。两个表的字段 A 和 B 具有相同的记录类型。我想从字段 A 和 B 的两个表中获取记录作为单个结果。
PHP+MySql中有Query或者Function吗?
谢谢...
最佳答案
SQL 中有一个联合子句可以满足您的需求:
select a,b from table1
where <where-clause>
union all select a,b from table2
where <where-clause>
或者,如果您想要所有字段(table2 的空格):
select a,b,c,d from table1
where <where-clause>
union all select a,b,' ' as c,' ' as d from table2
where <where-clause>
第二个查询中的空格可能需要扩展以适应 c 和 d 的字段大小。
关于php - 从多个表中抓取行作为单个结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/176774/