SQLTeam.com | Weblogs | Forums

Simple lookup and offset in sql

Hello, I'm very new in SQL.
i need to ask for a little help.

I've got big table and I need to add column like in excel lookup formula.
I'm trying to do by union or join but I'm stock.

ID_USER / NAME_USER / LAST_NAME_USER / ID_BOSS
I woudl like to add column in row for BOSS_NAME / BOSS_LAST_NAME

ID_USER / NAME USER / LAST_NAME_USER / ID BOSS
1 / AAAA / BIBBA / 872
2 / BBBB / GIKKO / 999
3 / CCCC / CICCO / 7
4 / GGGG / ALFA / 872
5 / RRRR / BETA / 999
()

Thanks in advanced. :slight_smile:

SELECT bt.ID_USER, bt.NAME_USER, bt.LAST_NAME_USER, bt._ID_BOSS,
btb.LAST_NAME AS BOSS_LAST_NAME
FROM big_table AS bt
LEFT OUTER JOIN big_table AS btb ON btb.ID_USER = bt.ID_BOSS

2 Likes

Thank you, It's work wonderful.