sql - MySQL ERROR 1349 What I am missing? -


i getting mysql 1349 error, appears though error incorrect:

error 1349: view's select contains subquery in clause 

can not have subqueries when creating view?

here sql:

create view  `wordpress`.`ffi_be_v_book_details` (   select ffi_be_courses. * , coalesce(  `total` , 0 )  `total`     `ffi_be_courses`    left join (     select * , count(  `course` )  `total`      ffi_be_courses     right join (       select  `course`         `ffi_be_bookcourses`        left join  `ffi_be_sale` on ffi_be_bookcourses.saleid = ffi_be_sale.saleid       date_add( ffi_be_sale.upload, interval(          select  `bookexpiremonths`           `ffi_be_settings` ) month ) > curdate( ) , ffi_be_sale.sold =  '0'       group ffi_be_bookcourses.saleid     )  `q1` on ffi_be_courses.code = q1.course     group q1.course   )  `q2` on ffi_be_courses.code = q2.code   ffi_be_courses.type =  'arts'   order ffi_be_courses.name asc ) 

thank time.

you missing fact views in mysql not allow subqueries in from clause. allowed in select , where , having clauses, however.

the documentation quite clear:

subqueries cannot used in clause of view.

in case, can rewrite from clause correlated subquery in select clause. can use multiple layers of views want.

edit:

a select statement in sql has following clauses: select, from, where, group by, having, , order by (according standard). in addition, mysql adds things limit, , into outfile. can see in way mysql describes select clause in documentation. can see in documentation database.

operations such join part of from clause (similarly with rollup part of group by , desc part of order by). these may seem arcane syntactic conventions, becomes important when there restriction 1 above.

perhaps 1 reason confusion indentation style goes like:

select . . . t1 inner join t2      on . . . 

where join statements line under select. misleading. write as:

select  t1 join      t2      on . . . 

only select clauses line under select.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -