We should take a look at the big picture, especially the SQL statement. But I suggest you CACtiveDataProvider with a advanced use of it possibilities. The use of SQL in a direct way must be avoid for getting a high quality code… Keep it so simple doesn’t mean a simple coding job… at all… keep communication bro…