i need to export a MySql Database to a SQLite database, im getting only the needed data from medias to make de SQLite database smaller as posible.
I have a Query that give to me only the animalsMedias or the plantsMedias that are related to the entry with the last version, published and not filed of an animal or a plant.
SELECT AM.*, max(A.version) AS version FROM animalsMedias AS AM INNER JOIN animals
AS A ON(AM.idAnimal = A.idAnimal AND A.filed = 0 AND A.published = 1) GROUP BY
A.idLanguaje, A.idVersion;
And to get only the medias related i try to make a SELECT on “medias” table that only returns to me the medias that are related with the result of the previous select, so i put both in “IN()”, but im getting the error:
#1241 - Operand should contain 1 column(s)
That is the query:
SELECT * from medias
WHERE idMedia IN(SELECT AM.*, max(A.version) AS version FROM
animalsMedias AS AM
INNER JOIN animals AS A ON(AM.idAnimal = A.idAnimal AND A.filed = 0
AND A.published = 1)
GROUP BY A.idLanguaje, A.idVersion)
OR idMedia IN(SELECT PM.*, max(P.version) AS version FROM plantsMedias AS PM
INNER JOIN plants AS P ON(PM.idPlant = P.idPlant AND P.filed = 0 AND P.published = 1)
GROUP BY P.idLanguaje, P.idVersion);
How can i get the “max(A.version)” if i must use only 1 operand?, if i understood good, inside IN i must have only “IN(SELECT AM.idMedia FROM….” to be correct.
Thanks in advice and sorry for my english, i try my best.
JOINthe tables instead of theseINpredicates: