I'm just started using SQL and ran into a problem.
In my database, I presently have two tables, Cinemas and Theatres. I'm trying to create a column "# of Theatres# in the Cinemas table that counts the number of Theatres in the Theatres table with the same CinemaID (foreign key) as a Cinema in the Cinemas table. I got it to work as an SQL query:
SELECT cinemas.CinemaID,Town,COUNT(*) AS '# of Theatres'
FROM cinemax.cinemas,cinemax.theatres
WHERE cinemas.CinemaID=theatres.CinemaID
GROUP BY cinemas.CinemaID;
But wanted to know if it's possible to create a column in the Cinemas table, that automatically performs the above query and inserts the value into each row.
It is going to be a very small database so speed isn't really an issue, I just want to learn how to make such a computed column (if even possible).
See Question&Answers more detail:os