Query in Query



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



  • 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...)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.