来自具有相同列名的两个表的数据 [英] Data from two tables with same column names

查看:34
本文介绍了来自具有相同列名的两个表的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张供用户使用的表.但是当用户对其个人资料进行任何更改时,我会将它们存储在临时表中,直到我批准它们.然后将数据复制到活动表并从临时表中删除.

I have a table for users. But when a user makes any changes to their profile, I store them in a temp table until I approve them. The data then is copied over to the live table and deleted from the temp table.

我想要实现的是,在管理面板中查看数据时,或者在用户提交前可以仔细检查的页面中,我想编写一个查询,允许我从两个表中获取数据两者中的 id 都等于 $userid.然后我想向他们显示一个表格形式,其中旧值出现在左列中,新值出现在右列中.

What I want to achieve is that when viewing the data in the admin panel, or in the page where the user can double check before submitting, I want to write a single query that will allow me to fetch the data from both tables where the id in both equals $userid. Then I want to display them a table form, where old value appears in the left column and the new value appears in the right column.

我找到了一些 sql 解决方案,但我不确定如何在 php 中使用它们来回显结果,因为两者中的列具有相同的名称.

I've found some sql solutions, but I'm not sure how to use them in php to echo the results as the columns in both have the same name.

推荐答案

AS 添加到列名称将允许您将其别名为不同的名称.

Adding AS to a column name will allow you to alias it to a different name.

SELECT table1.name AS name1, table2.name AS name2, ...
  FROM table1
  INNER JOIN table2
    ON ...

这篇关于来自具有相同列名的两个表的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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