I have the following SQL structure on Postgresql :
TABLE ei_1 :
╔══════╦════════╦══════╗
║ id ║ price ║ vat ║
╠══════╬════════╬══════╣
║ 1 ║ 10.0 ║ 0.20 ║
║ 2 ║ 15.0 ║ 0.20 ║
║ 3 ║ 20.0 ║ 0.20 ║
║ 4 ║ 25.0 ║ 0.20 ║
╚══════╩════════╩══════╝
TABLE ei_2
╔══════╦════════╦══════╗
║ id ║ price ║ vat ║
╠══════╬════════╬══════╣
║ 1 ║ 35.0 ║ 0.20 ║
║ 2 ║ 40.0 ║ 0.20 ║
║ 3 ║ 45.0 ║ 0.20 ║
║ 4 ║ 50.0 ║ 0.20 ║
╚══════╩════════╩══════╝
ei_3, ei_4 ... ei_x. The x is referenced in another table :
TABLE ei_info :
╔══════╗
║ id ║
╠══════╣
║ 1 ║
║ 2 ║
║ 3 ║
║ 4 ║
╚══════╝
How can I select information FROM the good ei_x according to the id in ei_info ? I saw people creating temporary tables but couldn't apply this to my case.
I am try to do a SELECT * FROM ei_x
Passing a var in a SQL table name is quite easy in most coding langages, but I don't know how to do it in SQL.
Any suggestions ?
eithat has a column to distinguish between the different "types". Do you have any chance fixing this bad design?ei_inforeferences. Does theidin there related to theidcolumn in the other tables? And what exactly is the output you want?