I've got problem when i want to display my data from multiple databases. It gives duplicate values.
So I have three databases in the same server. They have same table structure. So here is my query :
Query = 'SELECT id_movie, movie_tittle
FROM (SELECT id_movie, movie_tittle, status from margoplatinum.movie
UNION
SELECT id_movie, movie_tittle, status from detos21.movie
UNION
SELECT id_movie, movie_tittle, status from plaza21.movie) AS a
WHERE a.status = "Now Playing"'
It works but gives the duplicate values like this :
id_movies | movie_tittle
------------------------------------------
2 | THOR 2
1 | Gravity
3 | THOR 2
1 | The Legend of Hercules
4 | Gravity
So I put the DISTINCT
clauses like this :
Query = 'SELECT id_movie, DISTINCT (movie_tittle)
FROM (SELECT id_movie, movie_tittle, status from margoplatinum.movie
UNION
SELECT id_movie, movie_tittle, status from detos21.movie
UNION
SELECT id_movie, movie_tittle, status from plaza21.movie) AS a
WHERE a.status = "Now Playing"'
But the query above didn't work. It has an error message :
#1064 - 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 'DISTINCT (movie_tittle)
FROM (SELECT id_movie, movie_tittle, status from mar' at line 1
So how to write the SELECT DISTINCT from multiple databases?
Any help from you would be very helpful :) Thank you