I have 2 tables. (table1, table2) Now, I would like to do something along the lines of:
ALTER TABLE table1 ADD counter INT DEFAULT (Select COUNT(table2.car_type) FROM table2 WHERE (table1.car_type = table2.car_type));
That's the closest syntax I can come up with, but just by looking at it I know it's wrong. Please tell me how to do it in ONE SQL statement (if possible).
The goal table (with counter implemented) is something like this: (separated columns by -)
table1:
pid-car_type-counter
:
1-Honda-2
2-Toyota-3
3-Suzuki-1
4-Ferrari-0
5-Porsche-1
table2:
pid-car_type
:
1-Honda
2-Toyota
3-Porsche
4-Honda
5-Suzuki
6-Toyota
7-Toyota