Yii Criteria Condition Not Working Sql Error


$criteria->condition .= 'UserID = '.$userId.' UNION

(

    SELECT * FROM display WHERE 

    UserID IN 

    (

        SELECT DISTINCT UserID FROM lkusergroup WHERE 

        GroupID IN

        (

            SELECT GroupID FROM lkusergroup WHERE UserID = '.$userId.'

        )

    )

)';

i m trying to execute above code but getting following error


    CDbCommand failed to execute the SQL statement: SQLSTATE[21000]: 

Cardinality violation: 1222 The used SELECT statements have a different number of columns. The SQL statement executed was:

SELECT COUNT(*) FROM `display` `t` WHERE UserID = 2 UNION

        (

        SELECT * FROM display WHERE

        UserID IN

        (

        SELECT DISTINCT UserID FROM lkusergroup WHERE

        GroupID IN

        (

        SELECT GroupID FROM lkusergroup WHERE UserID = 2

        )

        )

    ) 

why query generating count(*) this is the actual issue. i tried may way to solve this error bt failed any suggestions ?

I suspect that it’s being generated to calculate the total number of rows that a grid view’s filters return. What specifically are you trying to do?