使用UNION创建MySQL视图 [英] Creating MySQL View using UNION
本文介绍了使用UNION创建MySQL视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为以下查询创建视图.
I am trying to create a view for the following query.
SELECT DISTINCT
products.pid AS id,
products.pname AS name,
products.p_desc AS description,
products.p_loc AS location,
products.p_uid AS userid,
products.isaproduct AS whatisit
FROM products
UNION
SELECT DISTINCT
services.s_id AS id,
services.s_name AS name,
services.s_desc AS description,
services.s_uid AS userid,
services.s_location AS location,
services.isaservice AS whatisit
FROM services
但不能这样做.我正在使用MySql查询浏览器.我收到的错误是:
But not able to do so. I am using MySql query browser. The error I am getting is:
只能从SELECT命令的活动结果集中创建视图
A view can only be created from an active resultset of SELECT command
有人可以帮我吗?
推荐答案
CREATE VIEW vw_product_services AS
SELECT DISTINCT products.pid AS id,
products.pname AS name,
products.p_desc AS description,
products.p_loc AS location,
products.p_uid AS userid,
products.isaproduct AS whatisit
FROM products
UNION
SELECT DISTINCT services.s_id AS id,
services.s_name AS name,
services.s_desc AS description,
services.s_uid AS userid,
services.s_location AS location,
services.isaservice AS whatisit
FROM services
我尝试了这个,它奏效了! 谢谢大家:)
I tried this and it worked! Thanks everyone :)
这篇关于使用UNION创建MySQL视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文