我收到错误#1349 - View's SELECT contains a subquery in the FROM clause
mycode是:
CREATE VIEW `MyViewName` AS
SELECT *
FROM
(SELECT *
FROM (
(SELECT *
FROM `crm_clients`
WHERE ctype=1
ORDER BY rand() LIMIT 0,
3)
UNION
(SELECT *
FROM `crm_clients`
WHERE ctype=1
ORDER BY rand() LIMIT 0,
3)
UNION
(SELECT *
FROM `crm_clients`
WHERE ctype=1
ORDER BY rand() LIMIT 0,
3)
UNION
(SELECT *
FROM `crm_clients`
WHERE ctype=1
ORDER BY rand() LIMIT 0,
3)) t
ORDER BY rand())
这段代码有什么问题?我对视图不是很熟悉
答案 0 :(得分:2)
在定义视图时,MySQL不允许from
子句中的子查询。
你可以做你想做的事:
Create View `MyViewName` as
(SELECT * FROM `crm_clients` WHERE ctype=1 order by rand() limit 0,3)
union
(SELECT * FROM `crm_clients` WHERE ctype=1 order by rand() limit 0,3)
union
(SELECT * FROM `crm_clients` WHERE ctype=1 order by rand() limit 0,3)
union
(SELECT * FROM `crm_clients` WHERE ctype=1 order by rand() limit 0,3)
order by rand();
我的猜测是你实际上也希望更改ctype
值。否则查询会很奇怪。
Here是对视图的限制。