Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Query in Query
Qt 6.12 LTS is out! See what's new in the release blog

Query in Query

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 991 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
    Zarkon
    wrote on last edited by
    #1

    I have a select query

    @QSqlQuery q;
    QString queryString;

    queryString.sprintf("select Application_ID from Applications where Application_name = '%s' and Application_major = %d and Application_minor=%d", application_info.Application_name.toLocal8Bit().data(), application_info.Application_major, application_info.Application_minor);

    if (!q.prepare(queryString)) {
    qDebug() << "Database error prepare";
    qDebug() << q.lastError();
    return;
    }
    if (!q.exec()) {
    qDebug() << "Database error exec";
    qDebug() << q.lastError();
    return;
    }@

    Now I want to do an update query that makes use of this select query. Is there a way to make use of 'q'? Like

    QSqlQuery upd;

    UPDATE "whatever fields" where application_id is in "query above"

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      The Query language depends of you database.
      you can do :
      UPDATE "whartever fields" where application_id in (select...)

      I think the best way to do it, if you already have the query result is :
      UPDATE "whartever fields" where application_id in (id1, id2...)

      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
      • Unsolved