如何在mysql中显示前3个输入



所以我写这个代码:

SELECT * FROM `data` WHERE 
`id`=(select max(`id`) from `data` 
WHERE `cat`='$data[cat]' and `id` < $data[id])

所以…怎么编辑呢…不仅显示一个结果,还显示$data[id]

的最后3个输入

试试这个

SELECT * from data WHERE 
`cat`='$data[cat]' and `id` < $data[id] 
order by id DESC LIMIT 0,3

试试这个

SELECT * FROM `data` id ORDER BY id DESC LIMIT 0 , 3

select 'data'表中插入的最后3行

SELECT * FROM `data` where  id IN ( select id from data where `cat`='$data[cat]' and `id` < $data[id])  ORDER BY id DESC LIMIT 0 , 3

第二个sql用于从特定值

中选择最后三行

Try order by with where子句

SELECT 
* 
FROM `data`  
WHERE `id` < $data[id]
ORDER BY id DESC 
LIMIT 0 , 3

将选择id小于data['id']的三行

相关内容

  • 没有找到相关文章

最新更新