Home > Backend Development > PHP Tutorial > 排序 让一个表中的数据依照另一个表排序

排序 让一个表中的数据依照另一个表排序

WBOY
Release: 2016-06-13 12:17:13
Original
1372 people have browsed it

排序 让一个表中的数据按照另一个表排序
比如表A有字段
id ,name
2   test
表B有字段  A表中的id等于B表中的 location_id

id  uid  location_id num  
1    1     2                  5
2   3      2                 6    
3   4      3                1

如何写sql语句让表A中的数据 按照表B中 num 排序 而且是总计的num 排序

------解决思路----------------------
select A.id,A.name from B inner join A on B.location_id = A.id order by B.num desc

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template