!!! Surprise!!! LAST is not a SQL Command

  • Thread starter Thread starter Mc_Clan
  • Start date Start date
M

Mc_Clan

Hi to all,

I search a solution to obtain a list with PHP from a DataBase MSSQL,
apparently simple.... ScansID, IP, OS... where IP fields are repeated,
I search to making my list in order to have the last IP in Function of
their ScansID? My colleague made a Query with Microsoft Acces.
I take the MSACCES query that it gives the good result: -

===================
SELECT MAX(Scan.ScansID) as MAXSCANSID, Scan.IP, LAST(Scan.OS) as LASTOS
FROM Scan GROUP BY Scan.IP
HAVING (((LAST(SCAN.OS)) IS NULL))
ORDER BY Scan.IP
===================

!!! Surprise!!! LAST is not a SQL Command (Tried also SQL Shell)

If you have idea of like helping me,

Thousand thanks
(also changing the structure of the query)

Thanks to all

McClan
 
Not only is LAST not a standard SQL aggregate function, it's a dubious one in
access because what it really does is give you the field value from some
arbitrary row in the table (same as FIRST). After all, in a relational
database, what order are records in? Why, the order you ask for them in using
ORDER BY, but ORDER BY can't inlude fields that are not part of the grouping
or part of an aggregate result, so it can't include the thing you want the
"last" of.

If you really do just need the field value from an arbitrary row, then you can
use MAX. If you really need some kind of Last item, you need to use some kind
of query of a query. If you can explain the requirement, I'm sure we can help
you formulate the SQL.
 
Back
Top