SELECT Info_key, Info_value, Info_status, Edit_time
F ROM (SELECT * from ' detail ' WHERE login = ' [e-mail protected] ' ORDER by Edit_time DESC) as AAA
GROUP by Info_key
Hope to realize the sub-query based on alias by Thinkphp, and finally refer to the following article to realize.
Http://www.thinkphp.cn/update/122.html
The following is the original text in the Help manual. (Search sub-query)
New subquery support has been added since version 3.0 and is available in two ways:
1, using the Select method when the parameter of the Select method is False, indicates that no query is returned only to build SQL, for example:
First construct the subquery sql $subQuery = $model->field (' Id,name ')->table (' tablename ')->group (' field ')->where ($where)- >order (' status ')->select (false);
When the Select method passes the false parameter, it means that the current query is not executed, but only the query SQL is generated.
2. Using the BuildSQL method
$subQuery = $model->field (' Id,name ')->table (' tablename ')->group (' field ')->where ($where)->order (' Status ')->buildsql ();
When the BuildSQL method is called, the actual query operation is not performed, but only the SQL statement that generated the query (in order to avoid confusion, the parentheses are added to the SQL), and then we call directly in subsequent queries.
Querying with subqueries $model->table ($subQuery. ' A ')->where ()->order ()->select ()
The constructed subquery SQL can be used for thinkphp's coherent operation methods, such as table where and so on.
ThinkPHP3.2 SQL alias subquery