php如何满足某一种条件,只取最新的一条数据

WBOY
Release: 2016-06-23 13:39:08
Original
1775 people have browsed it

SELECT * FROM pc_record WHERE name LIKE '小明' LIMIT 1
Copy after login



这种写法是随机取一条数据,我想取最新的一条,该怎么写

求大神指教


回复讨论(解决方案)

order by id desc
或者发布时间 desc

SELECT * FROM pc_record WHERE name LIKE '小明' order by id desc LIMIT 1

在语句后加order by id DESC

order by id desc,根据id从大到小排序,limit 1 取第一个,就是取id最大的那个,最新的那个 

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