0

I have a table where each row has several dates. How can I select the min of all the dates in the row?

Existing table:

Id Date_1 Date_2
1 2021/10/25 2021/03/15
2 2021/08/21 2021/12/04
3 2021/07/02 2021/09/11

Expected result:

Id Min_date
1 2021/03/15
2 2021/08/21
3 2021/07/02

Ideally something like: SELECT Id, least(Date_1, Date_2) from table

thought that doesn't work.

MatBailie
  • 83,401
  • 18
  • 103
  • 137
Jaol
  • 319
  • 1
  • 2
  • 10
  • 1
    Exactly what do you mean "doesn't work"? If it causes an error, include the error message in your question. If it runs, but doesn't return the desired results, include the results it currently returns in your question. – MatBailie Oct 30 '21 at 00:23
  • You might find this previous question useful, a couple of different ways are suggested, either using `CASE` statements or a `CROSS APPLY`: https://stackoverflow.com/questions/368351/whats-the-best-way-to-select-the-minimum-value-from-several-columns – 3N1GM4 Nov 03 '21 at 15:11
  • Does this answer your question? [What's the best way to select the minimum value from several columns?](https://stackoverflow.com/questions/368351/whats-the-best-way-to-select-the-minimum-value-from-several-columns) – 3N1GM4 Nov 03 '21 at 15:11

0 Answers0