QUERYing databases with Max clauses

QUERYing databases with Max clauses

  
So...hello everybody again! ;).

I want to know if its possible to query a database, and get the max value of a Date Time, for example. I'm reffering to normal query actions, not Advanced SQL actions!

Thank you in advance!

Dave
Hi Dave,

Using simple queries what you'd probably have to do is select the data and then loop through it finding the max value for the Date Time. You'd probably be much better using an Advanced Query.

Is there a specific reason why you wouldn't want to make use of an Advanced Query?

Cheers,
Richard
David Cuevas wrote:
So...hello everybody again! ;).

I want to know if its possible to query a database, and get the max value of a Date Time, for example. I'm reffering to normal query actions, not Advanced SQL actions!

Thank you in advance!

Dave
Hi David!

Easiest and build to change way, simple query with max records set to 1 and sort by the date field in descending order. Simple queries are optimized by the platform so if you only use the date attribute this is the only one fetched from the database. You can learn more about all this by watching our free online training in particular module 4 Model and Query Data

Cheers,
André 
 
Never thought about the sort field! Good plan Andre.
Hi,

Select MAX(fieldname) FROM <<tablename>>
WHERE
<<criteria>>

Thanks,

Mark
Hello,
Why don't you use an Advance Query?
Cleaner SQL and less SU's usage ;)

Regards,
Gonçalo M.
Hi Gonçalo.

I would say less performante (if you select more attributes than you need) and less portable... at least!
Hi Pedro,
That's another point of view..
Since David asked for a Max value of a single attribute I prefer to use a more readable SQL and to save some SU's (we have to save all we can since licences are getting more and more expensive)..
But your opinion is also valid, of course..
In fact Gonçalo, if it is a single column, it will be more readable.