且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

php pdo JOIN查询结果

更新时间:2023-02-26 10:19:54

您必须为一个表或另一个表的id列赋予列别名,以使列名不同.

You have to give a column alias to the id column from one table or the other to make the column names distinct.

这意味着您不能使用"SELECT *",您必须拼写要从该表中获取的列名称​​ all .如果您希望所有这些列都没有别名,那么至少您仍然可以查询category.*.

This means you can't use "SELECT *", you have to spell out all the column names you want to fetch from that table. At least you can still query for category.* if you want all those columns without aliasing.

顺便说一句,这类问题是避免在每个表的主键中使用通用名称(例如"id")的一个很好的理由.而是使用更具描述性的名称,例如product_idcategory_id.这样就不会出现列名冲突的问题.

By the way, this sort of problem is a good reason to avoid using a generic name like "id" for your primary key in every table. Instead use a more descriptive names like product_id and category_id. Then you won't have the problem of conflicting column names.