• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

bigger value in function MAX(x,y)

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone..

does someone know a way to get the bigger value between 2 values in a select statement?

example:

SELECT MAX(X, Y) FROM ...
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I could not understand well your question, but if you are looking to determine the max of two numbers, not in a table you have several choices, two of them are:
1) Create a strored function MX and
select MX(x,y) from dual
2)
select MAX(C) from (select 1 as C from dual
union all
select 2 as C from dual
)
Assuming that you are using oracle.
 
Fabiano Souza
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well,, sorry for confusion..

I was wondering if I could do something like this:

SELECT MAX (SELECT xc.price, (SELECT c.price FROM CPrice c WHERE c.id=?) FROM XPrice xc WHERE xc.id=?)



and thanks for replying!
 
Fabiano Souza
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just found what I needed

GREATEST..

SELECT GREATEST (xc.price, (SELECT c.price FROM CPrice c WHERE c.id=?)) FROM XCPrice xc WHERE xc.id=2262


Thanks again!!
 
Dany Mendez
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Still, if can do it like this:



SELECT MAX C from
(SELECT xc.price as C FROM XPrice xc WHERE xc.id=?)
union all
(SELECT c.price as C FROM CPrice c WHERE c.id=? )
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Fabiano Souza:
just found what I needed

GREATEST..

SELECT GREATEST (xc.price, (SELECT c.price FROM CPrice c WHERE c.id=?)) FROM XCPrice xc WHERE xc.id=2262


Thanks again!!



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:
Hello,

Still, if can do it like this:



SELECT MAX C from
(SELECT xc.price as C FROM XPrice xc WHERE xc.id=?)
union all
(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 ]
 
He does not suffer fools gladly. But this tiny ad does:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic