Different Outputs for Max() Function
Hi,
Please clarify how does the output of one is a single record/row and how does the output of
the second one is multiple records/rows
Let us consider emp table in Oracle
i wrote
Q1)select max(sal) from emp
now the output for the above statement might be 3600(lets say 3600 is the maximum salary)
Q2)select max(rowid) from emp
now the output for the above statement is of multiple rows. how does this happen
I would really appreciate if you could clarify the differences between how does the below work
a)max(sal)
b)max(rowid)
c)y the output of max(sal) is a single row record
d)y the output of max(rowid) is in multiple rows.
Re: Different Outputs for Max() Function
[B]>>select max(rowid) from emp
now the output for the above statement is of multiple rows. how does this happen[/B]
Rowid is a unique identifier for each row in a table.No two rows in a table will have same rowid.
Further Max function is a group function. Group functions always acts on set of records to return one result per each group. No chance to display two records or multiple records.
So it is impossibe to display multiple rows for folliwing query
select max(rowid) from emp
Re: Different Outputs for Max() Function
[B]select max(rowid) from emp[/B] will not return multiple rows .
Re: Different Outputs for Max() Function
you must having used group by clause in the query.
select max(rowid) from <table_name> group by <column_name>
in no condition select max(rowid) from <table_name> return multiple rows, untill 2 queries are joined using UNION, UNION ALL etc
Re: Different Outputs for Max() Function
I think there is no case that Select max(rowid) from <Tablename>; would give more than one single record unless and untill you use a group by clause.
These group functions works on the group of records. There is one more additional thing which I wan to share is that Max(), Min() and Count() are those group funtions, which can be used for any DATATYPE.