Linked Questions
63 questions linked to/from SQL MAX of multiple columns?
2
votes
3
answers
5k
views
Row-wise maximum in T-SQL [duplicate]
I've got a table with a few columns, and for each row I want the maximum:
-- Table:
+----+----+----+----+----+
| ID | C1 | C2 | C3 | C4 |
+----+----+----+----+----+
| 1 | 1 | 2 | 3 | 4 |
| 2 | ...
-6
votes
2
answers
33k
views
SQL MAX from multiple columns in a row [duplicate]
I need to fetch the maximum value from multiple columns in a single row.
The row looks like this:
Col1 || Col2 || Col3 || Col4 ||
100 || 120 || 130 || 140 ||
100 || 130 || 130 || 140 ||
100 |...
-1
votes
1
answer
9k
views
SQL Server select min date from 3 columns [duplicate]
I have a table with several date fields. I need to get a derived field that is the oldest date of 3 particular fields. I have to do this for 4 different date sets.
3
votes
4
answers
1k
views
Find Maximum(table.column1,table.column2,table.column3,...) as 'MaximumValue' from table SQL [duplicate]
SQL (SQL Server)
How to find maximum value among different columns in a single Table Row returned by a SQL Query.
Select Maximum(table.column1,table.column2,table.column3,...) as 'MaximumValue'
...
5
votes
7
answers
537
views
Get the Latest date from the Three columns [duplicate]
ID Date1 Date2 Date3
158 5/3/13 15:11 2/20/13 11:38 2/20/13 11:38
I want to get the latest date from this three columns.
2
votes
3
answers
414
views
Best Practice for returning the highest value in a set of columns? [duplicate]
SQL Isn't my Forte, Some help from you experts would be amazing :)
Dataset:
Name of Product | Part Number | Size 1 | Size 2 | Size 3
------------------|----------------|-----------|--------...
-2
votes
2
answers
632
views
Find the largest number from the SQL Table? [duplicate]
I was asked to find the largest number from the table (including all rows and columns) using SQL.
Here is the sample data. It should return 90 as the largest number.
row1 row2 row3
10 20 ...
-1
votes
2
answers
201
views
SQL- How to get MAX value with multiple columns BUT I only have 1 row [duplicate]
I'm trying to get the greatest value of just 1 row (mult columns). All of the tutorials I've watched are for multiple rows.
How can have just the greatest value (4943) returned?
Thanks!
-1
votes
1
answer
130
views
SQL SELECT Only the column with max date [duplicate]
I have a table with following data
villageId ChildID VC1_date VC2_date VC3_date VC4_date VC5_date
----------------------------------------------------------------------------
1 ...
0
votes
0
answers
82
views
how to select the oldest date among three columns in MS SQL Server [duplicate]
Say there is a table with columns of such:
date1, date2, date3, val1, val2, val3
2017-02-28, 2017-01-01, 2017-01-02, 100, 200, 300
2016-05-09, 2016-09-09, 2016-05-04, 2, 10, 20
I would like to get ...
-2
votes
2
answers
55
views
Get the max field value from each row [duplicate]
How Can I get the max value from few columns for each table row?
ID Date1 Date2
----------- ---------- ----------
1 2019-01-01 2019-12-29
result:
ID MaxDate ...
0
votes
0
answers
31
views
Effectively mimic T-SQL LEAST in earlier version (2017)? [duplicate]
So, I got myself in a situation where I have 36 columns and need to essentially do a "MIN" on ALL those columns. Not a MIN by grouping, rather, what I need is what the 2022-and-after LEAST ...
658
votes
31
answers
718k
views
Max function in SQL Server that takes two values like Math.Max in .NET
I want to write a query like this:
SELECT o.OrderId, MAX(o.NegotiatedPrice, o.SuggestedPrice)
FROM Order o
But this isn't how the MAX function works, right? It is an aggregate function so it expects ...
52
votes
13
answers
7k
views
Sort by minimum value of two columns
I use SQL Server 2008 R2.
I need to sort a table by the minimal value of two columns.
The table looks like this:
ID: integer;
Date1: datetime;
Date2: datetime.
I want my data to be sorted by ...
81
votes
4
answers
51k
views
MySQL: get MAX or GREATEST of several columns, but with NULL fields
I'm trying to select the max date in three different fields in each record (MySQL)
So, in each row, I have date1, date2 and date3: date1 is always filled, date2 and date3 can be NULL or empty
The ...