mySQL | View with Union – no brackets

CREATE VIEW ratemyhouse.v (level, id, dsc) AS
(SELECT 1 as level, object_id as id, object_desc as dsc
FROM object
WHERE object_prt IS NULL)
UNION
(SELECT 2 as level, t2.object_id as id, t2.object_desc as dsc
FROM object t1
LEFT JOIN object t2 ON t2.object_prt = t1.object_id
WHERE t1.object_prt IS NULL
AND t2.object_desc <> ”)
UNION
(SELECT 3 as level, t3.object_id as id, t3.object_desc as dsc
FROM object t1
LEFT JOIN object t2 ON t2.object_prt = t1.object_id
LEFT JOIN object t3 ON t3.object_prt = t2.object_id
WHERE t1.object_prt IS NULL
AND t3.object_desc <> ”)

http://stackoverflow.com/questions/9941226/mysql-cannot-create-view-that-contains-union

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s