on 11-27-2013 2:05 PM
SELECT ARBEI FROM VIAUFK_AFVC WHERE AUFPL = '1'
SELECT ARBEI FROM AFVV WHERE AUFPL = '1'
Answers on your 1 and 3 questions.
The select results from table and view are not necessarily the same. Simple explanation. If one table contains only 1 row and second contains 7 rows, the select from first table returns 1 row, but select from join returns:
1) 7 rows if values from join columns exists in both tables
2) 0 rows if values from join columns in first table doesn't exists in second table.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Roman,
Thank you for your answer. Actually this is natural, your hint helped me to realize the solution. This is how I understand it now:
1. Database must perform JOIN even if SELECT on view uses columns from single table AFVV.
Example:
Two tables: PERSON, CAR and view PERSON_CAR_VIEW joined on PERSON.CAR_ID and CAR.ID
Table PERSON contains only rows with null value for CAR_ID (no person with car).
Then:
SELECT NAME FROM PERSON WHERE AGE > 18
may find some rows from PERSON table but:
SELECT NAME FROM PERSON_CAR_VIEW WHERE AGE > 18
will find nothing due to no relation and empty CAR_ID in PERSON table.
2. Due to point 1 it is obvious that such SELECT on view will take more time than SELECT on single table (JOIN cannot be ignored).
If we are sure that we can ignore relations between tables, it is better to select directly from table and not redundant view.
Coming back to example from point 1 - the question is - should we search for adult persons at all, or only adult person who has a car (has filled CAR_ID relation). There is functional difference.
3. You hit the point with answer - it is possible that SELECT on single table may return more rows than SELECT on VIEW - as shown in example with PERSON and CAR.
Regards,
Adam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.