Home  >  Article  >  Backend Development  >  Thinkphp multi-table query has the perfect solution when two tables have the same fields repeated

Thinkphp multi-table query has the perfect solution when two tables have the same fields repeated

不言
不言Original
2018-06-07 11:34:503246browse

The following is a perfect solution for thinkphp multi-table query where the same fields are repeated in two tables. The content is quite good, so I will share it with you now and give it as a reference.

Framework: thinkphp

Version: 3.2.3

Content: Query statement

Solution to the problem: Duplicate field problem

$Data = M('a')->where($where)
  ->Field('a.name as aname,b.name as uname,a.*')
  ->join('b on b.jb_id=a.id')
  ->order('a.id desc')
  ->select();

Explanation: a.* Query all fields of table a

a .name as aname Convert the name repeated field in table a to aname

Related recommendations:

Analysis of form token errors and solutions under ThinkPHP

Solution to the temporary folder not found when uploading to PHP

The above is the detailed content of Thinkphp multi-table query has the perfect solution when two tables have the same fields repeated. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn