来自两个表的具有相同名称的mysql额外列 [英] mysql extra columns with same name from two tables

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

问题描述

表1中包含列:entry_id user_id ... 表2包含列:entry_id user_id ...

Table 1 has columns : entry_id user_id ... Table 2 has columns : entry_id user_id ...

user_id条目并不总是相同的,所以我想将它们都提取出来,以便以后可以在脚本中对它们进行比较

the user_id entry is not always the same so I would like to extract both of them so I can later on compare them in my script

SELECT * FROM 
table1 as t1
INNER JOIN table2 as t2 on t1.entry_id=t2.entry_id
WHERE t1.user_id='%s'

我想提取t1.user_id和t2.user_id ...问题是结果数组只有user_id

I would like to extract t1.user_id and t2.user_id ...the problem is the result array has only user_id

谢谢

推荐答案

使用AS关键字:

SELECT
  t1.user_id as t1_user_id
  ,t2.user_id as t2_user_id
FROM table1 as t1
INNER JOIN table2 as t2
  ON t1.entry_id=t2.entry_id
WHERE t1.user_id='%s'

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

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