Question

CREATE VIEW Te AS
SELECT
select sno,sname,dept,'madinah'as universty name from med_std
union
select sno,sname,dept,'yanbu'as universty name from yun_std
Was it helpful?

Solution

You have two SELECT statements in a row; remove one of them:

CREATE VIEW Te AS
select sno, sname, dept, 'madinah' as universty name from med_std
union
select sno, sname, dept, 'yanbu' as universty name from yun_std

Whilst you're at it you may want to seriously consider normalising your database; why does every university have a separate table? If you put it all in one table then you don't need to query multiple tables.

Furthermore, I'd highly recommend using UNION ALL in this situation if at all possible, instead of UNION. UNION will attempt to do a distinct sort on the result set; as your university's have different names between the two tables there is no need to do a distinct so you might just as well not attempt it. You should only use UNION if you want to remove duplicates from within one of your tables. See the documentation for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top