From the course: From Excel to SQL

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Using VLOOKUP, HLOOKUP, and XLOOKUP in SQL

Using VLOOKUP, HLOOKUP, and XLOOKUP in SQL

From the course: From Excel to SQL

Using VLOOKUP, HLOOKUP, and XLOOKUP in SQL

- If you want to combine data from different tables and worksheets in Excel, chances are you've reached for one of the various lookup functions that Excel provides. So, we're talking about VLOOKUP, HLOOKUP, or the newer XLOOKUP. If you take a look at the sample Excel spreadsheet on the sheet called Lookup State, you can see a simple example of this. Here, the State column has been filled using a VLOOKUP on the department data. And you might have done something similar to this before. Now, the bad news is there is no function called VLOOKUP, HLOOKUP, or XLOOKUP in SQL. The good news is they can still combine data from multiple tables by using the JOIN clause. So, let's take a look at how this same VLOOKUP in Excel can be easily performed in SQL. Let's open up DB Browser and click on the Execute SQL tab. If you want to list all the employees with their state information, you would use a JOIN like this. Firstly, let's select first name and last name, department and state for our columns,…

Contents