Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] How to combine multiple QSqlQueryModel?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to combine multiple QSqlQueryModel?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zither
    wrote on last edited by
    #1

    Dear all,

    I have the such database design.

    @USA_Table {name, phone, address}
    England_Table {name, phone, address}
    Norway_Table {name, phone, address}
    India_Table {name, phone, address}
    ..
    ..
    ..@

    I would like to search name in all tables, return result must be in
    @Result_Table {name, phone, address}@

    I can't find SQL solution to get such result, how to do to get such result?
    Need to combine multiple QSqlQueryModels in a view?

    Thanks

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      With a UNION SELECT you can combine the tables in one query...

      bq. The SQL UNION is used to combine the results of two or more SELECT SQL statements into a single result. All the statements concatenated with UNION must have the same structure. This means that they need to have the same number of columns, and corresponding columns must have the same or compatible data types (implicitly convertible to the same type or explicitly converted to the same type). The columns in each SELECT statement must be in exactly the same order too.
      This is how a simple UNION statement looks like:
      @SELECT Column1, Column2 FROM Table1
      UNION
      SELECT Column1, Column2 FROM Table2@
      The column names in the result of a UNION are always the same as the column names in the first SELECT statement in the UNION.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Bad design, if you ask me. Somthing like this makes much more sense, at least from a database normalization perspective:

        Countries {ID, Country}
        Contacts {ID, Name, Telefone, Address, CountryID}

        That will make the UNION select Eddy suggested also no longer needed.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved