Search code examples
mysqldatabaseviewupdatable-views

Should multiple tables be referenced in the SELECT statement when creating a mysql view?


http://www.mysqltutorial.org/create-sql-updatable-views.aspx

This article above states the following:

SELECT statement must not reference to more than one table. It means it must not contain more than one table in FROM clause, other tables in JOIN statement, or UNION with other tables.

Is this true and why? How would you query two related tables like it was one (through a view), without using joins in every query string?


Solution

  • When you create a view you are already combining the tables. What they are trying to say is that you should not have a SELECT statement, in general, that JOINs a View and a Table. Although you CAN do this, it is not the best practice. The point of a View is to create a Table that has Fields from multiple Tables that you constantly call on a regular basis. A View is more efficient than JOINing Tables on every SELECT statement for those multiple tables.