选择具有连接的多个列,并保持与选择中相同的名称

时间:2023-02-08 13:17:30

I'm doing a SQL Request and I want to know if I can keep the same name as the name that I use in my select

我正在做一个SQL请求,我想知道我是否可以保留与我在select中使用的名称相同的名称

Exemple :

例子:

SELECT users.id, users.block, users.login, users.address
FROM users 
LEFT JOIN users_info ON users.id = users_info.id

I want to get the column like

我希望得到这样的专栏

users.id | users.block | users.login | users.address

But I got it like that

但我得到了这样的

id | block | login | address

And I want to know if there is another way as to do it with alias

而且我想知道是否有另一种方法可以用别名来做

SELECT users.id as users.id , users.block as users.block , users.login as users.login , users.address as users.address
FROM users 
LEFT JOIN users_info ON users.id = users_info.id

I'm working with pdo on php, someone know a function that can send the table name with the field when i fetchAll ?

我正在使用php上的pdo,有人知道一个函数可以在我fetchAll时用字段发送表名吗?

Thanks !

谢谢 !

2 个解决方案

#1


3  

You have to put the name between backticks or single quotes

你必须把名字放在反引号或单引号之间

SQL DEMO

SQL DEMO

For example:

例如:

select version() as `mysql.version`

select version() as 'mysql.version'

#2


0  

I will use fetch instead of fetchAll and PDOStatement::getColumnMeta(nbFetch)["table"] in each fetch then copy it in another array !

我将在每次获取中使用fetch而不是fetchAll和PDOStatement :: getColumnMeta(nbFetch)[“table”],然后将其复制到另一个数组中!

Thanks for help !

感谢帮助 !

#1


3  

You have to put the name between backticks or single quotes

你必须把名字放在反引号或单引号之间

SQL DEMO

SQL DEMO

For example:

例如:

select version() as `mysql.version`

select version() as 'mysql.version'

#2


0  

I will use fetch instead of fetchAll and PDOStatement::getColumnMeta(nbFetch)["table"] in each fetch then copy it in another array !

我将在每次获取中使用fetch而不是fetchAll和PDOStatement :: getColumnMeta(nbFetch)[“table”],然后将其复制到另一个数组中!

Thanks for help !

感谢帮助 !