How to use query data for another sql query in yii2

I have a query here:




      public function SearchExactJob($id) {

          $connect = \Yii::$app->db;

          

          $query = $connect->createCommand('

               SELECT job_name FROM job_questions WHERE job_id=:id')

               ->bindValue(':id':$id)

               ->queryAll();


    }



I want to use the job_name for another query: PS: I just wrote this down on a paper in case i’ll be able to find out how to get this data




      $anotherquery = $connect->createCommand(

                      'SELECT * FROM company_questions

                       WHERE company_question = [the job_name I want to get from the `$query`])



Also if I will successfully get the $anotherquery work, I want to get the data and pass it on the view assigned to this.

But then, im asking for help because I just recently used Yii2. Please help me.

From first query something like




$jobname = $query->job_name;



now you have $jobname to bind in next query.

If you are just getting one result change


->queryAll();

to


->queryOne(\PDO::FETCH_OBJ);

FETCH_OBJ easier for me anyway to work with.

thanks! it worked for me. :)