Question

I am creating a view with the query shown below:

create view v2 as
(select * from appearance a
where exists (
    select p.id from photo p, photographer u, person s
    where p.takenBy = u.id
    and u.id = s.id
    and a.isShownIn = p.id
    and s.name = 'Fred'
    )
);

The appearance table has 2 columns 'shows' and 'isShownIn' but when i try to insert in the view, it gives me error as Error Code: 1054. Unknown column 'a.isShownIn' in 'where clause'

While browsing over this I cam over that I am mistaking over alias, but everything looks OK to me, could anyone please point out where could be the error?

Thanks!

Was it helpful?

Solution

You will not be able to insert in a view created in that way. Only certain views are updateable. In your specific case, you should just insert into appearance table, since your view is just a selection from that table.

For limitations for updateable views, check this out. Your view has this problem: "A subquery in the WHERE clause that refers to a table in the FROM clause"

Like @Umbrella suggested, you can use join instead of exists, and in that way, you would avoid inner query, and you might have updateable view, but I really think that there is no need to insert into that view, because you will have the same effect by just inserting into appearance table.

OTHER TIPS

Why are you using exists()? Why not just join them...

create view v2 as
select a.* 
from appearance a, photo p, photographer u, person s
where a.isShownIn = p.id
  and p.takenBy = u.id
  and u.id = s.id
  and s.name = 'Fred'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top