Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Favorites infavorites:mine
infavorites:1234
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with Search options answers only user 993

Finding the maximum value in a group of items

6
votes
That should be GREATEST(), not MAX(). MAX() is for aggregating over values from rows, GREATEST() is for aggregating over a list of values (from columns, expressions). You can either find the 3 max … values, one for each column and then the greatest of the three: select greatest(max(col1), max(col2), max(col3)) from mytable ; or find the greatest value in each row and then the max over all of them: select max(greatest(col1, col2, col3)) from mytable ; …
answered Sep 28 '16 by ypercubeᵀᴹ
2
votes
You don't need a subquery for this. It can be simple and more efficient: SELECT id_product, date FROM products WHERE fk_stat = 1 AND id_order = 77185 ORDER BY id_product DESC LIMIT 1 ;
answered Jul 21 '15 by ypercubeᵀᴹ
4
votes
Assuming that you want - if the max(number) in the whole table is say, 27 - to update all the rows with NULL, to 28. You need a subquery or a derived table to first find this max and then join back … to the table: UPDATE tableX AS t CROSS JOIN ( SELECT MAX(number) AS max_number FROM tableX ) AS m SET t.number = m.max_number + 1 WHERE t.number IS NULL ; …
answered Jun 18 '16 by ypercubeᵀᴹ
4
votes
The function is called GREATEST() GREATEST returns the greatest of a list of one or more expressions. Oracle Database uses the first expr to determine the return type. If the first expr is numeric …
answered Sep 5 '18 by ypercubeᵀᴹ
0
votes
This would be easily solved with window functions in other DBMS that have implemented these features, like PostgreSQL, Oracle, DB2 or with a LATERAL join inj Postgres (or the similar CROSS/OUTER APPLY …
answered Jan 15 '16 by ypercubeᵀᴹ
3
votes
I think you want multiple aggregations: First find the max for each ID-Source combination, then sum for every ID: select ID, sum(MaxNumImages) as SumMaxNumImages from ( select ID, max
answered Jul 9 by ypercubeᵀᴹ