mysql - Need to fix a sub-query and can't figure what went wrong -


i used sub-query returns orders placed on last day of activity can found in orders table.

here came with:

select orderid, orderdate, customerid, employeeid orders orderdate = max(orderdate); 

this received: msg 147, level 15, state 1, line 3 aggregate may not appear in clause unless in subquery contained in having clause or select list, , column being aggregated outer reference.

where did go wrong?

your error translates to: cannot use max() unless use group by or like.

so here's quick way rewrite query:

select orderid, orderdate, customerid, employeeid orders orderdate = (select top 1 orderdate orders order orderdate desc); 

but orderdate potentially timestamped, add well:

select orderid, orderdate, customerid, employeeid orders orderdate = dateadd(dd, 0, datediff(dd, 0, (select top 1 orderdate orders order orderdate desc))); 

i realize isn't mysql, hope or else able rewrite solution mysql you.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -