1) Create a strored function MX and
select MX(x,y) from dual
select MAX(C) from (select 1 as C from dual
select 2 as C from dual
Assuming that you are using oracle.
Originally posted by Fabiano Souza:
just found what I needed
SELECT GREATEST (xc.price, (SELECT c.price FROM CPrice c WHERE c.id=?)) FROM XCPrice xc WHERE xc.id=2262
You shouldn't put your query inside the function and should join the table and use it on the result... otherwise you will be peforming a query within the function for every row returned.
It should look more like this:
Originally posted by Dany Mendez:
Still, if can do it like this:
SELECT MAX C from
(SELECT xc.price as C FROM XPrice xc WHERE xc.id=?)
(SELECT c.price as C FROM CPrice c WHERE c.id=? )
No, that would only give you the maximum value for C within your inline view... it would not tell you the highest price on each row within your table. In otherwords it would return a single value for your union, regardless of the number of rows queried.
Also... you should have parentheses around "C" in your example (MAX(C)).
[ December 10, 2008: Message edited by: Paul Campbell ]