edited by
1,423 views
2 votes
2 votes

Can we apply min and max (aggregate function in sql) on strings and date datatype ?

Query :SELECT max(Name) FROM EMPLOYEE

what will be the result ?

edited by

2 Answers

Best answer
2 votes
2 votes

Yes ,we apply Max,MIn Function function on string and date date type.

In case of String data type-The functions Max ,Min, etc. use the lexicographic order when applied to text columns.

If Query is-

SELECT MAX(`type`) FROM 'Product`;

Output-

Printer

In PC and Laptop case: "P" symbol goes after "L" symbol(P>L) so MAX result is PC. Printer and PC: first letters are equal (P=P)but "r" symbol goes after "C"(r>c) so MAX result is Printer.

In case of Date data type-

Query-SELECT MAX(return_date)  FROM `movies`;

Output- 

25-06-2012

above query give latest date.

From your Table and query result is- 'F'

selected by
0 votes
0 votes
for non-numeric values we use ascii() function

it returns numeric value of left most charecter

Related questions

2 votes
2 votes
1 answer
1
rohan mishra asked Jul 8, 2017
1,338 views
Given a column consisting of 12,19,12,13,14,NULL,NULL. What will be the answer1.If we apply count on the column.2.If we apply sum on the column.3.If we apply avg on the ...
0 votes
0 votes
1 answer
3
Satbir asked Dec 4, 2018
288 views
please give an example to differentiate between self join , natural join and join operation.
1 votes
1 votes
1 answer
4
Harikesh Kumar asked Jan 13, 2018
397 views
Provide the correct answer