Skip to content
Advertisement

add auto generate column with correlated subqueries in mysql

I want to add a column that auto generates value depending on other tables. There are 2 tables to work with.

Table “finance” :

Table “price” :

And by executing this command

I get this result

I wanted to make the revenue_x_10 auto generated by doing something like this.

But looks like I can only put columns from the same table then calculate new ones on them. How can I make the revenue_x_10 as a column generated automatically on the “price” table.

Reason why I want to do something like this is because performance issues. I’m working with relatively big dataset, like a couple thousand row on the “price” and dozen rows on the “finance”. And sometimes I need to do this for couple thousand tables. By using queries it’s just too slow to do.

Advertisement

Answer

As mentioned by gordon, it can not refer to other tables while it comes to auto generate.

You can create a view with not exists as follows:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement