我在查询中使用左外连接。但是现在我得到了双重身份证, 我的意思是我现在得到表1的id和table2的id都叫id。
有没有办法可以用类似的方式重命名(前缀)表2的id table2_id?无需使用' AS table_nameOfColumn'对于表2的每一栏
我当前的查询:
SELECT invoices.*, clients.* FROM invoices
LEFT OUTER JOIN users ON invoices.employee_id = users.id
LEFT OUTER JOIN clients ON users.client_id = clients.id
WHERE invoices.employee_id = 3
答案 0 :(得分:1)
您只需为明确命名的列名称添加别名
即可例如:
SELECT invoices.id as invoce_id, clients.id as client_id FROM invoices
LEFT OUTER JOIN users ON invoices.employee_id = users.id
LEFT OUTER JOIN clients ON users.client_id = clients.id
WHERE invoices.employee_id = 3