I have three tables in database
tableA
tableB
tableC
All these three table have document_date.
I need eloquent with model for
max(
( max of document_date in table A) Union
( max of document_date in table B) Union
( max of document_date in table C)
)
The result should be one date.
2
Answers
you should join those tables then use mysql greatest function:
I think it need some tweaks to match your DB, but there is the main idea
I’d execute three separate queries selecting the largest date per table and then checking which one is the highest using plain PHP. Otherwise your queries will quickly become a tangled mess. Unless this is for some highly optimized production application, the premature optimization will definitely not outweigh the speed gained by combining it into a singular query.
Example
Psuedo-code
Pro’s
Cons