求一个多表查询的sql语句
A表10个字段
字段分别为aid, title, cid, content, atime, aorder, acount,a1, a2, mtime
B表9个字段
字段分别为bid, title, cid, content, btime, border, b3, b4, mtime
现在我获取到一个关键词$kw,我需要同时搜索A表和B表的title字段,获取到所有like %$kw%的所有记录,并根据mtime来排序。
获取的记录里,需要保留的字段有a(b)id,title,cid,content,mtime这几个。
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> $sql = 'SELECT '; $sql .= 'A.aid as id,B.bid AS id,'; $sql .= 'A.title as title,B.title as title,'; $sql .= 'A.cid as cid,B.cid as cid,'; $sql .= 'A.content as content,B.content as content,'; $sql .= 'A.mtime as mtime,B.mtime as mtime'; $sql .= 'FROM A,B WHERE title like "%'.$kw.'%" ORDER BY mtime DESC';
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号