我有四张桌子,分别是分配表、用户表、车辆表和燃油表。我想创建一个返回唯一行的查询(也就是说,除了users表之外,每个表都应该只有一个惟一的id)。
我希望查询返回最近的条目(类似于最后一个条目)。
我当前的查询在下面,但它返回它找到的第一行,而不是最后一行
Select distinct
v.vname,
v.year,
v.make,
v.model,
v.vid,
v.fueltype,
f.fID,
f.meter,
f.date,
a.driverID,
a.dateassigned,
u.uid,
u.name,
u.surname
from
vehicles as v,
assigns as a,
users as u,
fuel as f
where
v.vid = a.vID
and
a.driverID = u.id
and
v.vid = f.vID
group by
v.vid
order by
f.date desc
如何使用这些表从数据库中获取最后一个条目?
最佳答案
尝试使用以下限制代码:
Select distinct
v.vname,
v.year,
v.make,
v.model,
v.vid,
v.fueltype,
f.fID,
f.meter,
f.date,
a.driverID,
a.dateassigned,
u.uid,
u.name,
u.surname
from
vehicles as v,
assigns as a,
users as u,
fuel as f
where
v.vid = a.vID
and
a.driverID = u.id
and
v.vid = f.vID
group by
v.vid
order by
f.date desc
limit 1
关于php - 从数据库获取最新条目,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50576221/