From the course: Querying Microsoft SQL Server 2022

Unlock the full course today

Join today to access over 24,200 courses taught by industry experts.

Find the GREATEST or LEAST value

Find the GREATEST or LEAST value - SQL Server Tutorial

From the course: Querying Microsoft SQL Server 2022

Find the GREATEST or LEAST value

- [Instructor] There are two new functions that have been added to SQL Server 2022 that'll help you compare numbers and text strings across multiple columns in the same row, they're called greatest and least. Let's see how they work by selecting all of the first and last names of all of the people in the person's table. I'll also sort these names by the business entity ID so that they're not in an alphabetical order in the results. Let me execute the query so we can see the raw data that we're about to work with. Okay, now we can compare each person's first name to their last name and find out which one comes first alphabetically. To do that, we'll use the new greatest function. The greatest function takes multiple arguments and these are the columns that hold the values that you want to compare. In our case, I'm going to compare the first name values to the last name values. I'll name the results of this greatest…

Contents