1

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?

Keeper Hood
  • 594
  • 5
  • 17

3 Answers3

3

That page is about updatable views, and the condition of being able to update the underlying table via the view means you have to place some more restrictions on the contents of the view, in order for mysql to be able to map your update back to the underlying table.

If you just want to read from a view without the need to update the underlying table using it, you can select from more than one table using joins, UNIONs, etc, in a view definition.

marnir
  • 1,187
  • 10
  • 13
0

It is only true for updateable views. If you couldn't link up more than 1 table in a view, then the whole point of a view would be meaningless :)

Michael J.V.
  • 5,499
  • 1
  • 20
  • 16
-1

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.

bdparrish
  • 3,216
  • 3
  • 37
  • 58
  • thanks, i guess i haven't understood well what they were trying to say – Keeper Hood Jun 05 '11 at 11:08
  • thanks, Johan you have been badged as jackass...there is nothing wrong with what I said. It was my fault for not writing in context of the article that he was refering to, but in context of just his question. – bdparrish Jun 09 '11 at 16:53