i need to select distinct value from a multiple union.
I nee to use union on multiple table on different databases.
But i i try to use this code:
SELECT DISTINCT name ((SELECT name FROM tab1) UNION (SELECT name FROM tab2))
i have this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION (SELECT name FROM tab2 )' at line 1
You dont need to use “distinct”. UNION gives you the distinct result already.
This give you the correct result.By the way, if you want to fetch data from different database you need to use db name.Please refer following for this;