Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to Query (join) two tables from two different sqlite databases?



  • I want to query data from two tables.

    eg.
    SELECT M.ID, M.Name, M.Year, M.Type, P.MoviePicture FROM Movie as M LEFT JOIN Movie_Image as P ON M.NO=P.NO
    Above statement is ok when two tables exist with single database.

    My Problem is table named Move is within myMove.db.
    Other table named Movie_Image is within myPicture.db.

    Hello!How to Query (join) two tables from two different sqlite databases?

    Thanks.


  • Lifetime Qt Champion

    Hi
    Its possible via
    https://sqlite.org/lang_attach.html

    However, i have not tested if it works in connection with Qt database classes.



  • I got to thinking about this and realized this might be a really good use of a temporary memory database. You could:

    • query the tables of each respective database
    • create a temporary memory database in sqlite
    • create 2 tables from each query of each respective table
    • do a join query on the two tables
    • use the data
    • delete the temporary memory database

    The neat thing is this should work regardless of the features of the source databases. They could even be completely different types of SQL (or even non sql) databases.

    One database to join them all and in the memory bind them...


Log in to reply