Thinkphp method to query duplicate databases: 1. Instantiate the data table through "$test_data = M('hot');"; 2. Use "testdata>Distincttrue)->field(descriprion')- >orderdescription desc->select" method or use the group method to remove duplicates.
The operating environment of this tutorial: Windows 7 system, ThinkPHP version 5, Dell G3 computer.
thinkphp How to query duplicate databases?
thinkphp database duplication checking method
$test_data = M('hot');//实例化数据表 $data=$testdata>Distincttrue)->field(descriprion')->orderdescription desc->select: //利用distinct方法去重 $data=$test_data->group("description')->order('description desc')->select(); //利用group方法去重 dump($data);
For two deduplication methods:
Use distinct to deduplicate, simple and easy to use, but it can only be used for a single field Heavy, and the final result is only the fields with the duplicate removed, and the actual application value is not particularly great.
Using group to remove duplication, the final display result is all fields, and a single field is deduplicated. The effect is good, but the final display result is sorted according to the first field except for the deduplication field. May still need to be processed.
Recommended learning: "thinkPHP Video Tutorial"
The above is the detailed content of How to query duplicate database in thinkphp. For more information, please follow other related articles on the PHP Chinese website!