1

I have table, which looks like this

 id | item | price1 | price2

I want do get the list of items and for every item I want also to select max price among price1 and price2. Is it possible to do that in one query? Something like

SELECT item, max(price1,price2) FROM table;

UPDATE

Example:

table contains

item1 | 4 | 8
item2 | 5 | 1
item3 | 7 | 7

I want result to be

item1 | 8
item2 | 5
item3 | 7
2
  • Can you show what an example of what you expect the result to look like? Commented Jun 6, 2015 at 16:27
  • use max(price1), max(price2) a group by and a case statement to select the larger of the two as your the final output signal Commented Jun 6, 2015 at 16:28

1 Answer 1

1

Use GREATEST :

SELECT GREATEST(1, 100);
┌──────────┐
│ greatest │
├──────────┤
│      100 │
└──────────┘
(1 row)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.