Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在通过 PDO 在一对连接表上运行查询,如下所示:
SELECT table1.id, table2.id, table1.foo, table1.bar FROM table1 INNER JOIN table2 ON table1.bar = table2.id;
两个表都有一id列,所以当我运行fetchAll()关联数组时只包含一个id字段。这是因为第一个被第二个覆盖。
id
fetchAll()
有没有办法获得这两个id领域?也许通过将表名包含在数组键中......
使用别名
SELECT table1.id as t1id, table2.id as t2id --etc.
尝试这个
SELECT table1.id AS idtable1, table2.id AS idtable2, table1.foo, table1.bar FROM table1 INNER JOIN table2 ON table1.bar = table2.id;