Creating MySQL View using UNION

后端 未结 5 1824
逝去的感伤
逝去的感伤 2021-02-14 06:18

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 descri         


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-14 06:43

    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 :)

提交回复
热议问题