Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Question: How to avoid 200 If-Else Statements?

Tags:

sql

ms-access

I've following tables with the attributes

Table1: [username]    [old_profile]
Table2: [old_profile] [new_profile]
Table3: [username]    [new_profile]    [some_more_attributes]

Table2 declares the rules for renaming "old_profile" into "new_profile" (e.g. if the old_profile was called "Banana300", the new_profile should be called "Chocolate125").

Does anyone know if it's possible to execute that with a SQL/MS Access Query?

If not, I would have to write an external script for this task.

Thanks a lot.

Cheers

EDIT: I forgot to explicitly mention that I want to create Table3 from Table1 and Table2 (ignore the "some_more_attributes").

like image 606
Joseph jun. Melettukunnel Avatar asked Jun 21 '11 12:06

Joseph jun. Melettukunnel


1 Answers

If I understood your question:

INSERT INTO table3 (username, newprofile) 
SELECT t1.username, t2.newprofile
FROM table1 t1 INNER JOIN table2 t2 ON t1.oldProfile = t2.OldProfile
like image 179
iDevlop Avatar answered Sep 23 '22 06:09

iDevlop